[SLOF] [PATCH] lib/libnet/ipv6: Silence compiler warning from Clang

Thomas Huth thuth at redhat.com
Mon Jun 27 18:26:32 AEST 2022


When compiling the libnet code with Clang (e.g. for the s390-ccw bios),
it complains with the following warning:

 ipv6.c:447:18: warning: variable length array folded to constant array
  as an extension [-Wgnu-folding-constant]
                unsigned short raw[ip6size];
                               ^
The warning is completely harmless, of course. Anyway let's rewrite the
code a little bit to make the compiler silent again.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 lib/libnet/ipv6.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/libnet/ipv6.c b/lib/libnet/ipv6.c
index 6420004..259087b 100644
--- a/lib/libnet/ipv6.c
+++ b/lib/libnet/ipv6.c
@@ -441,10 +441,9 @@ static unsigned short ip6_checksum(struct ip6hdr *ip6h, unsigned char *packet,
 {
 	int i;
 	unsigned long checksum;
-	const int ip6size = sizeof(struct ip6hdr)/sizeof(unsigned short);
 	union {
 		struct ip6hdr ip6h;
-		unsigned short raw[ip6size];
+		uint16_t raw[sizeof(struct ip6hdr) / sizeof(uint16_t)];
 	} pseudo;
 
 	memcpy (&pseudo.ip6h, ip6h, sizeof(struct ip6hdr));
@@ -455,7 +454,7 @@ static unsigned short ip6_checksum(struct ip6hdr *ip6h, unsigned char *packet,
 	for (checksum = 0, i = 0; i < bytes; i += 2)
 		checksum += (packet[i] << 8) | packet[i + 1];
 
-	for (i = 0; i < ip6size; i++)
+	for (i = 0; i < (int)(sizeof(pseudo.raw) / sizeof(pseudo.raw[0])); i++)
 		checksum += pseudo.raw[i];
 
 	checksum = (checksum >> 16) + (checksum & 0xffff);
-- 
2.31.1



More information about the SLOF mailing list