]> The Tcpdump Group git mirrors - libpcap/commitdiff
usb-linux: Address a -Wformat-truncation= compiler warning
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 14 Aug 2020 20:55:41 +0000 (22:55 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 14 Aug 2020 21:04:27 +0000 (23:04 +0200)
Moreover:
Fix indent.

The warning was:
./pcap-usb-linux.c: In function 'usb_read_linux':
./pcap-usb-linux.c:903:37: warning: '%s' directive output may be
truncated writing up to 4095 bytes into a region of size 227
[-Wformat-truncation=]
  868 |  char *string = line;
      |                 ~~~~
......
  903 |       "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
      |                                     ^~
./pcap-usb-linux.c:903:7: note: directive argument in the range [-2147483648, 7]
  903 |       "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./pcap-usb-linux.c:902:3: note: 'snprintf' output between 66 and 4171
bytes into a destination of size 256
  902 |   snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  903 |       "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  904 |       string, ret);
      |       ~~~~~~~~~~~~

pcap-usb-linux.c

index 98d22de4c865ed42c9d403da649042bb753ae50c..436a8452b825c564537fffebd2c50b6f6faf40b5 100644 (file)
@@ -899,9 +899,13 @@ usb_read_linux(pcap_t *handle, int max_packets _U_, pcap_handler callback, u_cha
                &cnt);
        if (ret < 8)
        {
+               char string_truncated[181];
+
+               strncpy(string_truncated, string, sizeof(string_truncated));
+               string_truncated[180] = 0;
                snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
-                   "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
-                   string, ret);
+                        "Can't parse USB bus message '%s', too few tokens (expected 8 got %d)",
+                        string_truncated, ret);
                return -1;
        }
        uhdr->id = tag;