]> The Tcpdump Group git mirrors - libpcap/commitdiff
Address another -Wformat-truncation warning.
authorDenis Ovsienko <[email protected]>
Wed, 18 Jul 2018 14:33:29 +0000 (15:33 +0100)
committerDenis Ovsienko <[email protected]>
Wed, 18 Jul 2018 14:36:50 +0000 (15:36 +0100)
add_dev() does not imply a particular string length for the name and the
description, so it is OK just to increase the buffer size to make the
description fit. While at it, use sizeof() for snprintf() and unsigned
props for the unsigned structure members from <bluetooth/hci.h>.

./pcap-bt-linux.c: In function ‘bt_findalldevs’:
./pcap-bt-linux.c:115:58: warning: ‘%d’ directive output may be truncated writing between 1 and 10 bytes into a region of size 5 [-Wformat-truncation=]
   pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
                                                          ^~
./pcap-bt-linux.c:115:32: note: directive argument in the range [0, 2147483646]
   pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pcap-bt-linux.c

index 07ed1c73de5a47cdec8601c5116641a3b0d2c208..15c2c1c520c7c5ee89aa89f4e47cced53f05c84b 100644 (file)
@@ -74,7 +74,8 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
 {
        struct hci_dev_list_req *dev_list;
        struct hci_dev_req *dev_req;
-       int i, sock;
+       int sock;
+       unsigned i;
        int ret = 0;
 
        sock  = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
@@ -109,10 +110,10 @@ bt_findalldevs(pcap_if_list_t *devlistp, char *err_str)
 
        dev_req = dev_list->dev_req;
        for (i = 0; i < dev_list->dev_num; i++, dev_req++) {
-               char dev_name[20], dev_descr[30];
+               char dev_name[20], dev_descr[40];
 
-               pcap_snprintf(dev_name, 20, BT_IFACE"%d", dev_req->dev_id);
-               pcap_snprintf(dev_descr, 30, "Bluetooth adapter number %d", i);
+               pcap_snprintf(dev_name, sizeof(dev_name), BT_IFACE"%u", dev_req->dev_id);
+               pcap_snprintf(dev_descr, sizeof(dev_descr), "Bluetooth adapter number %u", i);
 
                /*
                 * Bluetooth is a wireless technology.