]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: quic: Compilation fixes for some gcc warnings with -O1
authorFrédéric Lécaille <flecaille@haproxy.com>
Mon, 3 Jul 2023 12:31:13 +0000 (14:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 3 Jul 2023 12:50:54 +0000 (14:50 +0200)
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

index 15a8d945babc87c642a376c9df61224d36f0f2a4..24686e082f1707c08431d39dcc754b1571e2b967 100644 (file)
@@ -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 <qel> 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 <cbuf>.
                 */