From 2ebb93359682cb354a94b8873737587f478b009e 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. (cherry picked from commit 16e1e44c5ef96d28663208b005cc3343b95ba634) (cherry picked from commit 286bb2f029bc11cda9f62bdbb429b0da9b3b77eb) (cherry picked from commit b474ed004497d229329ff19fb48c8c2d1ca636e7) --- 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 456871a78d..f925bbbec0 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -197,6 +197,7 @@ ethtool_get_stringset (SocketHandle *shandle, int stringset_id) struct ethtool_sset_info info; guint32 sentinel; } sset_info = { }; + const guint32 *pdata; gs_free struct ethtool_gstrings *gstrings = NULL; guint32 i, len; @@ -209,7 +210,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 = g_malloc0 (sizeof (*gstrings) + (len * ETH_GSTRING_LEN)); gstrings->cmd = ETHTOOL_GSTRINGS;