From f4d9fa4089e6bd5c3c79501fcc5dbfa6af3cb3dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Mon, 3 Jul 2023 14:31:13 +0200 Subject: [PATCH] BUILD: quic: Compilation fixes for some gcc warnings with -O1 This is to prevent the build from these gcc warning when compiling with -O1 option: willy@wtap:haproxy$ sh make-native-quic-memstat src/quic_conn.o CPU_CFLAGS="-O1" CC src/quic_conn.o src/quic_conn.c: In function 'qc_prep_pkts': src/quic_conn.c:3700:44: warning: potential null pointer dereference [-Wnull-dereference] 3700 | frms = &qel->pktns->tx.frms; | ~~~^~~~~~~ src/quic_conn.c:3626:33: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized] 3626 | if (end - pos < QUIC_INITIAL_PACKET_MINLEN) { | ~~~~^~~~~ --- src/quic_conn.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/quic_conn.c b/src/quic_conn.c index 15a8d945b..24686e082 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -3574,6 +3574,8 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf, padding = 0; pos = (unsigned char *)b_head(buf); first_pkt = prv_pkt = NULL; + end = pos; // just to let gcc know it will always be initialized + while (b_contig_space(buf) >= (int)qc->path->mtu + dg_headlen || prv_pkt) { int err, probe, cc, must_ack; enum quic_pkt_type pkt_type; @@ -3696,6 +3698,11 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf, next_tel = QUIC_TLS_ENC_LEVEL_APP; tel = next_tel; qel = qc_quic_enc_level(qc, tel); + + /* This cannot happen. This is to please some compilers. */ + if (!qel || !qel->pktns) + goto end_of_dgram; + /* Note that we cannot NULL as value for when for the Application * data encryption level. Furthermore this encryption is never released. */ @@ -3711,6 +3718,7 @@ static int qc_prep_pkts(struct quic_conn *qc, struct buffer *buf, } } + end_of_dgram: /* If we have to build a new datagram, set the current datagram as * prepared into . */