From ddccf7bcee550c5bbdddbaa2abbd34833a7c9585 Mon Sep 17 00:00:00 2001 From: Steven Luong Date: Fri, 18 Jan 2019 22:53:18 -0800 Subject: Fix GCC 8 compiler warnings on strncpy's truncated copy on debian distro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For some reason, GCC 8 in debian is pickier than GCC 8 in ubuntu. It complains about things in strncpy like this /home/sluong/vpp/src/vlib/linux/pci.c:485:7: error: ‘strncpy’ output may be truncated copying 15 bytes from a string of length 255 [-Werror=stringop-truncation] strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/sluong/vpp/src/vlib/linux/pci.c: At top level: It also complains similar things in string_test.c The fix in pci.c is to convert strncpy to use clib_strncpy The fix in string_test.c is condiational compile the complained code for GCC 8. Change-Id: Ic9341ca54ed7407210502197a28283bc42c26662 Signed-off-by: Steven Luong --- src/vlib/linux/pci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/vlib') diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c index ee3eebfbd83..d31b3c94d62 100644 --- a/src/vlib/linux/pci.c +++ b/src/vlib/linux/pci.c @@ -466,7 +466,7 @@ vlib_pci_bind_to_uio (vlib_main_t * vm, vlib_pci_addr_t * addr, clib_memset (&ifr, 0, sizeof ifr); clib_memset (&drvinfo, 0, sizeof drvinfo); ifr.ifr_data = (char *) &drvinfo; - strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); + clib_strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); drvinfo.cmd = ETHTOOL_GDRVINFO; if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) @@ -482,7 +482,7 @@ vlib_pci_bind_to_uio (vlib_main_t * vm, vlib_pci_addr_t * addr, continue; clib_memset (&ifr, 0, sizeof (ifr)); - strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); + clib_strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0) { -- cgit 1.2.3-korg