From 013b0f806ecfeff3ab4b1fe744ca7db690368269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Lepp=C3=A4nen?= Date: Mon, 12 Jun 2023 13:55:49 +0300 Subject: [PATCH] linux-gen: pktio: fix flexible array member error in pedantic compilation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When compiling with GCC 13.1 and -Wpedantic, struct sset_info causes the error "invalid use of structure with flexible array member [-Werror=pedantic]". The flexible array member in this case is the data member of struct ethtool_sset_info. In order to reserve space for it, turn sset_info into a union, and make the next member in the union the size of struct ethtool_sset_info and the data. Signed-off-by: Jere Leppänen Reviewed-by: Janne Peltonen --- platform/linux-generic/pktio/stats/ethtool_stats.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/pktio/stats/ethtool_stats.c b/platform/linux-generic/pktio/stats/ethtool_stats.c index deb00bf59c..bbf0729f17 100644 --- a/platform/linux-generic/pktio/stats/ethtool_stats.c +++ b/platform/linux-generic/pktio/stats/ethtool_stats.c @@ -29,9 +29,11 @@ static struct ethtool_gstrings *get_stringset(int fd, struct ifreq *ifr) { - struct { + union { struct ethtool_sset_info hdr; - uint32_t buf[1]; /* overlaps with hdr.data[] */ + /* Reserve space for hdr.data. */ + uint8_t buf[sizeof(struct ethtool_sset_info) + + sizeof(((struct ethtool_sset_info *)0)->data[0])]; } sset_info; struct ethtool_drvinfo drvinfo; uint32_t len;