From: Willy Tarreau Date: Wed, 2 Apr 2025 14:07:31 +0000 (+0200) Subject: BUILD: quic_sock: address a strict-aliasing build warning with gcc 5 and 6 X-Git-Tag: v3.2-dev9~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd900aead8613af12ea23b18a3e77d28ad42729b;p=thirdparty%2Fhaproxy.git BUILD: quic_sock: address a strict-aliasing build warning with gcc 5 and 6 The UDP GSO code emits a build warning with older toolchains (gcc 5 and 6): src/quic_sock.c: In function 'cmsg_set_gso': src/quic_sock.c:683:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *((uint16_t *)CMSG_DATA(c)) = gso_size; ^ Let's just use the write_u16() function that's made for this purpose. It was verified that for all versions from 5 to 13, gcc produces the exact same code with the fix (and without the warning). It arrived in 3.1 with commit 448d3d388a ("MINOR: quic: add GSO parameter on quic_sock send API") so this can be backported there. --- diff --git a/src/quic_sock.c b/src/quic_sock.c index b7ee8f8f4..1da0743f1 100644 --- a/src/quic_sock.c +++ b/src/quic_sock.c @@ -680,7 +680,7 @@ static void cmsg_set_gso(struct msghdr *msg, struct cmsghdr **cmsg, c->cmsg_level = SOL_UDP; c->cmsg_type = UDP_SEGMENT; c->cmsg_len = CMSG_LEN(sz); - *((uint16_t *)CMSG_DATA(c)) = gso_size; + write_u16(CMSG_DATA(c), gso_size); #endif }