diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-02-01 11:38:57 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-02-03 11:00:34 +0100 |
commit | 6345a661535bd4aaf62b2ba4bee129762abb2954 (patch) | |
tree | 935814664256a514d7d7e3f8c31d9d7fa890a3d6 | |
parent | 207e971863976aa96b319ca652190cfc3bc2b5c0 (diff) | |
download | NetworkManager-6345a661535bd4aaf62b2ba4bee129762abb2954.tar.gz |
platform: fix GCC warning about zero-lenght array (1)
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:
src/platform/nm-platform-utils.c: In function ‘ethtool_get_stringset’:
src/platform/nm-platform-utils.c:355:27: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u32[0]’ {aka ‘unsigned int[0]’} [-Werror=zero-length-bounds]
355 | len = sset_info.info.data[0];
| ~~~~~~~~~~~~~~~~~~~^~~
In file included from src/platform/nm-platform-utils.c:12:
/usr/include/linux/ethtool.h:647:8: note: while referencing ‘data’
647 | __u32 data[0];
| ^~~~
Fix this warning.
-rw-r--r-- | src/platform/nm-platform-utils.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 4f0da581d0..f907d298d1 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -335,24 +335,25 @@ _ethtool_call_once (int ifindex, gpointer edata, gsize edata_size) static struct ethtool_gstrings * ethtool_get_stringset (SocketHandle *shandle, int stringset_id) { - struct { - struct ethtool_sset_info info; - guint32 sentinel; - } sset_info = { - .info.cmd = ETHTOOL_GSSET_INFO, - .info.reserved = 0, - .info.sset_mask = (1ULL << stringset_id), - }; + char buf[sizeof (struct ethtool_sset_info) + sizeof (guint32)]; + struct ethtool_sset_info *sset_info; gs_free struct ethtool_gstrings *gstrings = NULL; gsize gstrings_len; guint32 i, len; - if (_ethtool_call_handle (shandle, &sset_info, sizeof (sset_info)) < 0) + sset_info = (struct ethtool_sset_info *) buf; + *sset_info = (struct ethtool_sset_info) { + .cmd = ETHTOOL_GSSET_INFO, + .reserved = 0, + .sset_mask = (1ULL << stringset_id), + }; + + if (_ethtool_call_handle (shandle, sset_info, sizeof (*sset_info)) < 0) return NULL; - if (!sset_info.info.sset_mask) + if (!sset_info->sset_mask) return NULL; - len = sset_info.info.data[0]; + len = sset_info->data[0]; gstrings_len = sizeof (*gstrings) + (len * ETH_GSTRING_LEN); gstrings = g_malloc0 (gstrings_len); |