From 5076fc0ca0e22b3db7987df561922d9efa840f26 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sat, 1 Feb 2020 11:39:16 +0100 Subject: [PATCH] platform: fix GCC warning about zero-lenght array (2) 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 ‘nmp_utils_ethtool_get_permanent_address’: src/platform/nm-platform-utils.c:854:29: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u8[0]’ {aka ‘unsigned char[0]’} [-Werror=zero-length-bounds] 854 | if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) { ./shared/nm-glib-aux/nm-macros-internal.h:731:20: note: in definition of macro ‘_NM_IN_SET_EVAL_N’ Fix this warning. --- src/platform/nm-platform-utils.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c index f907d298d1..492572833e 100644 --- a/src/platform/nm-platform-utils.c +++ b/src/platform/nm-platform-utils.c @@ -832,41 +832,42 @@ nmp_utils_ethtool_get_permanent_address (int ifindex, guint8 *buf, size_t *length) { - struct { - struct ethtool_perm_addr e; - guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1]; - } edata = { - .e.cmd = ETHTOOL_GPERMADDR, - .e.size = NM_UTILS_HWADDR_LEN_MAX, - }; + char ebuf[sizeof (struct ethtool_perm_addr) + NM_UTILS_HWADDR_LEN_MAX + 1]; + struct ethtool_perm_addr *edata; guint i; g_return_val_if_fail (ifindex > 0, FALSE); - if (_ethtool_call_once (ifindex, &edata, sizeof (edata)) < 0) + edata = (struct ethtool_perm_addr *) ebuf; + *edata = (struct ethtool_perm_addr) { + .cmd = ETHTOOL_GPERMADDR, + .size = NM_UTILS_HWADDR_LEN_MAX, + }; + + if (_ethtool_call_once (ifindex, edata, sizeof (*edata)) < 0) return FALSE; - if (edata.e.size > NM_UTILS_HWADDR_LEN_MAX) + if (edata->size > NM_UTILS_HWADDR_LEN_MAX) return FALSE; - if (edata.e.size < 1) + if (edata->size < 1) return FALSE; - if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) { + if (NM_IN_SET (edata->data[0], 0, 0xFF)) { /* Some drivers might return a permanent address of all zeros. * Reject that (rh#1264024) * * Some drivers return a permanent address of all ones. Reject that too */ - for (i = 1; i < edata.e.size; i++) { - if (edata.e.data[0] != edata.e.data[i]) + for (i = 1; i < edata->size; i++) { + if (edata->data[0] != edata->data[i]) goto not_all_0or1; } return FALSE; } not_all_0or1: - memcpy (buf, edata.e.data, edata.e.size); - *length = edata.e.size; + memcpy (buf, edata->data, edata->size); + *length = edata->size; return TRUE; }