From 16e1e44c5ef96d28663208b005cc3343b95ba634 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 10 Feb 2020 10:55:12 +0100 Subject: [PATCH] platform: fix GCC warning about zero-length array in ethtool_get_stringset() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/platform/nm-platform-utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index 4f0da581d0..39bf719bae 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -343,6 +343,7 @@ ethtool_get_stringset (SocketHandle *shandle, int stringset_id) .info.reserved = 0, .info.sset_mask = (1ULL << stringset_id), }; + const guint32 *pdata; gs_free struct ethtool_gstrings *gstrings = NULL; gsize gstrings_len; guint32 i, len; @@ -352,7 +353,9 @@ ethtool_get_stringset (SocketHandle *shandle, int stringset_id) if (!sset_info.info.sset_mask) return NULL; - len = sset_info.info.data[0]; + pdata = (guint32 *) sset_info.info.data; + + len = *pdata; gstrings_len = sizeof (*gstrings) + (len * ETH_GSTRING_LEN); gstrings = g_malloc0 (gstrings_len);