diff options
author | Marco Varlese <marco.varlese@suse.com> | 2018-06-27 09:54:44 +0200 |
---|---|---|
committer | Chris Luke <chris_luke@comcast.com> | 2018-07-09 12:28:30 +0000 |
commit | ca7a68e0fba9de14e18801c535d87da7fa0e4fa3 (patch) | |
tree | 82a017053a7500ab9a886310dc2014b5a0055a50 | |
parent | 6bb589c8acc4e3c27bcbd84d9fcd98ba0777db36 (diff) |
gcc8 and Wstringop-truncation
gcc8 introduced a new warning (Wstringop-truncation) which in our case
is being treated as error.
Disabling the warning globally might introduce bugs related to string
truncation which are not desired by the developer (e.g. bug).
Instead, this patch disables the warning only for those occurences
which have been verified to be non-bugs but the desired behaviour as per
developer will.
Change-Id: I0f04ff6b4fad44061e80a65af633fd7e0148a0c5
Signed-off-by: Marco Varlese <marco.varlese@suse.com>
(cherry picked from commit 99d7a72cbcad959e805e8e8b5efb112e9def69c2)
-rw-r--r-- | src/plugins/memif/memif_api.c | 2 | ||||
-rw-r--r-- | src/vlib/linux/pci.c | 6 | ||||
-rw-r--r-- | src/vlibmemory/vlib_api.c | 10 | ||||
-rw-r--r-- | src/vnet/devices/virtio/vhost-user.c | 4 |
4 files changed, 13 insertions, 9 deletions
diff --git a/src/plugins/memif/memif_api.c b/src/plugins/memif/memif_api.c index 6cb48a8f72d..a4137e48006 100644 --- a/src/plugins/memif/memif_api.c +++ b/src/plugins/memif/memif_api.c @@ -130,7 +130,7 @@ void if (len > 0) { vec_validate (socket_filename, len); - strncpy ((char *) socket_filename, (char *) mp->socket_filename, len); + memcpy (socket_filename, mp->socket_filename, len); } rv = memif_socket_filename_add_del (is_add, socket_id, socket_filename); diff --git a/src/vlib/linux/pci.c b/src/vlib/linux/pci.c index 11480ca081c..7cadb1378ec 100644 --- a/src/vlib/linux/pci.c +++ b/src/vlib/linux/pci.c @@ -442,7 +442,8 @@ vlib_pci_bind_to_uio (vlib_pci_addr_t * addr, char *uio_drv_name) memset (&ifr, 0, sizeof ifr); memset (&drvinfo, 0, sizeof drvinfo); ifr.ifr_data = (char *) &drvinfo; - strncpy (ifr.ifr_name, e->d_name, IFNAMSIZ - 1); + strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name)); + ifr.ifr_name[ARRAY_LEN (ifr.ifr_name) - 1] = '\0'; drvinfo.cmd = ETHTOOL_GDRVINFO; if (ioctl (fd, SIOCETHTOOL, &ifr) < 0) { @@ -457,7 +458,8 @@ vlib_pci_bind_to_uio (vlib_pci_addr_t * addr, char *uio_drv_name) continue; memset (&ifr, 0, sizeof (ifr)); - strncpy (ifr.ifr_name, e->d_name, IFNAMSIZ - 1); + strncpy (ifr.ifr_name, e->d_name, sizeof (ifr.ifr_name)); + ifr.ifr_name[ARRAY_LEN (ifr.ifr_name) - 1] = '\0'; if (ioctl (fd, SIOCGIFFLAGS, &ifr) < 0) { error = clib_error_return_unix (0, "ioctl fetch intf %s flags", diff --git a/src/vlibmemory/vlib_api.c b/src/vlibmemory/vlib_api.c index 1067bf3b4ba..cdf6b873ad2 100644 --- a/src/vlibmemory/vlib_api.c +++ b/src/vlibmemory/vlib_api.c @@ -109,9 +109,8 @@ vl_api_get_first_msg_id_t_handler (vl_api_get_first_msg_id_t * mp) if (am->msg_range_by_name == 0) goto out; - - strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name) - 1); - + strncpy ((char *) name, (char *) mp->name, ARRAY_LEN (name)); + name[ARRAY_LEN (name) - 1] = '\0'; p = hash_get_mem (am->msg_range_by_name, name); if (p == 0) goto out; @@ -157,7 +156,10 @@ vl_api_api_versions_t_handler (vl_api_api_versions_t * mp) rmp->api_versions[i].major = htonl (vl->major); rmp->api_versions[i].minor = htonl (vl->minor); rmp->api_versions[i].patch = htonl (vl->patch); - strncpy ((char *) rmp->api_versions[i].name, vl->name, 64 - 1); + strncpy ((char *) rmp->api_versions[i].name, vl->name, + ARRAY_LEN (rmp->api_versions[i].name)); + rmp->api_versions[i].name[ARRAY_LEN (rmp->api_versions[i].name) - 1] = + '\0'; } vl_api_send_msg (reg, (u8 *) rmp); diff --git a/src/vnet/devices/virtio/vhost-user.c b/src/vnet/devices/virtio/vhost-user.c index c1fca441fa5..781836d8bd1 100644 --- a/src/vnet/devices/virtio/vhost-user.c +++ b/src/vnet/devices/virtio/vhost-user.c @@ -3191,8 +3191,8 @@ vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm, vuid->is_server = vui->unix_server_index != ~0; vuid->sock_errno = vui->sock_errno; strncpy ((char *) vuid->sock_filename, (char *) vui->sock_filename, - ARRAY_LEN (vuid->sock_filename) - 1); - + sizeof (vuid->sock_filename)); + vuid->sock_filename[ARRAY_LEN (vuid->sock_filename) - 1] = '\0'; s = format (s, "%v%c", hi->name, 0); strncpy ((char *) vuid->if_name, (char *) s, |