diff options
author | Stephen Hemminger <stephen@networkplumber.org> | 2019-01-16 10:23:16 -0800 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-01-17 09:19:33 +0000 |
commit | 4e8a83183e9a381d6c44fa3b94faf735d536e811 (patch) | |
tree | 4294a6c241a18c6c7aef5724bd686143ee837766 | |
parent | ef080e1f9bad884b95ef23307b0d856c971dfcc2 (diff) |
pci: fix strncpy warnings
Doing strncpy(ifr.ifr_name, s, sizeof(ifr.ifr_name)) will cause
a warning about string truncation with GCC 8 (and other tools).
Fix this by using sizeof(ifr.ifr_name) - 1. Also, there is no
need to manually zero the end of the string since the whole
ifr structure is already zeroed by memset.
Change-Id: I9440d602ecdd9f8592b69bab2e77479146d00d76
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r-- | src/vlib/linux/pci.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c index b99f54f2a62..ee3eebfbd83 100644 --- a/src/vlib/linux/pci.c +++ b/src/vlib/linux/pci.c @@ -466,8 +466,8 @@ 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)); - ifr.ifr_name[ARRAY_LEN (ifr.ifr_name) - 1] = '\0'; + strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); + drvinfo.cmd = ETHTOOL_GDRVINFO; if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) { @@ -482,8 +482,8 @@ 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)); - ifr.ifr_name[ARRAY_LEN (ifr.ifr_name) - 1] = '\0'; + strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name) - 1); + if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0) { error = clib_error_return_unix (0, "ioctl fetch intf %s flags", |