libusb_util.c: Avoid gcc warning about strncpy()

What we're doing is actually legal: We copy the full size of the
destination array, and then overwrite the last byte with NUL.  However,
gcc isn't smart enough to see that:

libusb_util.c:162:5: warning: ‘strncpy’ specified bound 20 equals destination size [-Wstringop-truncation]
     strncpy(out[out_idx].path, path, sizeof(out[out_idx].path));
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Let's copy one byte less to make it happy.

Change-Id: Iae13f7a4cf89230f308eb0183d993d7c31024907
This commit is contained in:
Harald Welte 2018-10-12 15:16:43 +02:00
parent 61df6c309c
commit 8bb639ac3b
1 changed files with 1 additions and 1 deletions

View File

@ -159,7 +159,7 @@ int dev_find_matching_interfaces(libusb_device *dev, int class, int sub_class, i
out[out_idx].vendor = dev_desc.idVendor;
out[out_idx].product = dev_desc.idProduct;
out[out_idx].addr = addr;
strncpy(out[out_idx].path, path, sizeof(out[out_idx].path));
strncpy(out[out_idx].path, path, sizeof(out[out_idx].path)-1);
out[out_idx].path[sizeof(out[out_idx].path)-1] = '\0';
out[out_idx].configuration = conf_desc->bConfigurationValue;
out[out_idx].interface = if_desc->bInterfaceNumber;