Change in osmo-remsim[master]: libusb_util.c: Avoid gcc warning about strncpy()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Oct 14 18:55:03 UTC 2018


Harald Welte has uploaded this change for review. ( https://gerrit.osmocom.org/11345


Change subject: libusb_util.c: Avoid gcc warning about strncpy()
......................................................................

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
---
M src/simtrace2/libusb_util.c
1 file changed, 1 insertion(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-remsim refs/changes/45/11345/1

diff --git a/src/simtrace2/libusb_util.c b/src/simtrace2/libusb_util.c
index cb435e2..45e3f50 100644
--- a/src/simtrace2/libusb_util.c
+++ b/src/simtrace2/libusb_util.c
@@ -159,7 +159,7 @@
 				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;

-- 
To view, visit https://gerrit.osmocom.org/11345
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-remsim
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iae13f7a4cf89230f308eb0183d993d7c31024907
Gerrit-Change-Number: 11345
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181014/87281395/attachment.htm>


More information about the gerrit-log mailing list