From dc85fbc3e13b0463399a64468169ee18698771ab Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 12 Oct 2018 15:15:08 +0200 Subject: [PATCH] libusb_util.c: Avoid gcc warning about strncpy() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: I30ddacdc73e5245c7c38b92d1e94e39b13fae7d3 --- host/libusb_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/libusb_util.c b/host/libusb_util.c index cb435e2b..45e3f50d 100644 --- a/host/libusb_util.c +++ b/host/libusb_util.c @@ -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;