diff options
author | Benoît Ganne <bganne@cisco.com> | 2020-04-24 10:33:40 +0200 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2020-04-29 15:18:52 +0000 |
commit | 3a76dc3f4f32b8af6bd4bb2486008b6ba73a848f (patch) | |
tree | 60399ca56b2631c57f18b91253792445bafab427 /src/vnet/devices | |
parent | 28adbb3aef75d087eda8df2463de46ac378c8b00 (diff) |
devices: vhost: simplify string copies for GCC-10
GCC-10 increases string truncations warnings. Refactor string copies
confusing it.
Type: refactor
Change-Id: I9720a0539059de00ab212ff2fc73055f04f5af1d
Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vnet/devices')
-rw-r--r-- | src/vnet/devices/virtio/vhost_user.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/vnet/devices/virtio/vhost_user.c b/src/vnet/devices/virtio/vhost_user.c index d24e516a93c..1883f862742 100644 --- a/src/vnet/devices/virtio/vhost_user.c +++ b/src/vnet/devices/virtio/vhost_user.c @@ -1819,7 +1819,6 @@ vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm, vhost_user_intf_details_t *vuid = NULL; u32 *hw_if_indices = 0; vnet_hw_interface_t *hi; - u8 *s = NULL; int i; if (!out_vuids) @@ -1841,17 +1840,13 @@ vhost_user_dump_ifs (vnet_main_t * vnm, vlib_main_t * vm, vuid->num_regions = vui->nregions; vuid->is_server = vui->unix_server_index != ~0; vuid->sock_errno = vui->sock_errno; - strncpy ((char *) vuid->sock_filename, (char *) vui->sock_filename, - 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, - ARRAY_LEN (vuid->if_name) - 1); - _vec_len (s) = 0; + snprintf ((char *) vuid->sock_filename, sizeof (vuid->sock_filename), + "%s", vui->sock_filename); + memcpy_s (vuid->if_name, sizeof (vuid->if_name), hi->name, + clib_min (vec_len (hi->name), sizeof (vuid->if_name) - 1)); + vuid->if_name[sizeof (vuid->if_name) - 1] = 0; } - vec_free (s); vec_free (hw_if_indices); *out_vuids = r_vuids; |