]> git.kaiwu.me - haproxy.git/commitdiff
IMPORT: uslz: fix a build warning with gcc -O1
authorWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2026 10:56:22 +0000 (11:56 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 1 Dec 2026 13:09:51 +0000 (14:09 +0100)
At -O1, gcc emits this warning because it doesn't clearly see that all
paths reach this place with sym properly initialized:

  src/uslz.c: In function 'uslz_eob_follows':
  src/uslz.c:745:18: warning: 'sym' may be used uninitialized in this function [-Wmaybe-uninitialized]
    745 |         if (!ret || sym != 256)
        |             ~~~~~^~~~~~~~~~~~~

Let's just preset it to zero. Unfortunately it slightly inflates the code
with more instructions and stack usage because the compiler does not see
that the called functions don't use it, but it has almost no impact on
measured performance. Another approach consists in passing the pointer to
state->symbol, but even if it reduces the code, it suffers a bigger slowdown
likely due to having to access the member that's a bit colder in the cache.

This is slz commit 544c4d5cca. No backport to haproxy stable versions is
needed.

src/uslz.c

index 3632e2f5395a5f9ec9898c0b65550879166040dd..fb296341b0f6786c08b5d2ed5b7409ec03732400 100644 (file)
@@ -731,7 +731,7 @@ int uslz_eob_follows(struct uslz_stream *state)
        unsigned long bit_accum = state->bit_accum;
        unsigned char num_bits = state->num_bits;
        unsigned int hi = state->huff_index;
-       unsigned int sym;
+       unsigned int sym = 0;
        int ret;
 
        if (state->dec_bsize < state->out_max || state->state != USLZ_ST_READ_SYMBOL)