From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] tcp: Work around gcc 12 bogus warning in tcp_rtt_dst_check() Date: Fri, 20 May 2022 11:01:11 +0200 Message-ID: <20220520090111.2510593-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============2976044405441419218==" --===============2976044405441419218== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable gcc 12.1.x (e.g. current OpenSUSE Tumbleweed, x86_64 only, gcc-12-1.4.x86_64) reports: tcp.c: In function =E2=80=98tcp_send_flag=E2=80=99: tcp.c:1014:9: warning: writing 16 bytes into a region of size 0 [-Wstringop-o= verflow=3D] 1014 | memcpy(low_rtt_dst + hole++, &conn->a.a6, sizeof(conn->a.a6)); | ^ tcp.c:559:24: note: at offset -16 into destination object =E2=80=98low_rtt_ds= t=E2=80=99 of size 128 559 | static struct in6_addr low_rtt_dst[LOW_RTT_TABLE_SIZE]; | but 'hole' can't be -1, because the low_rtt_dst table is guaranteed to have a hole: if we happened to write to the last entry, we'll go back to index 0 and clear that one. Signed-off-by: Stefano Brivio --- tcp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tcp.c b/tcp.c index e68409a..53af3db 100644 --- a/tcp.c +++ b/tcp.c @@ -1011,6 +1011,12 @@ static void tcp_rtt_dst_check(const struct tcp_conn *c= onn, hole =3D i; } =20 + /* Keep gcc 12 happy: this won't actually happen because the table is + * guaranteed to have a hole, see the second memcpy() below. + */ + if (hole =3D=3D -1) + return; + memcpy(low_rtt_dst + hole++, &conn->a.a6, sizeof(conn->a.a6)); if (hole =3D=3D LOW_RTT_TABLE_SIZE) hole =3D 0; --=20 2.35.1 --===============2976044405441419218==--