]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: http_htx: silence uninitialized warning on some gcc versions
authorWilly Tarreau <w@1wt.eu>
Fri, 1 Dec 2023 14:29:44 +0000 (15:29 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Dec 2023 19:46:24 +0000 (20:46 +0100)
Building on gcc 4.4 reports "start may be used uninitialized". This is
a classical case of dependency between two variables where the compiler
lost track of their initialization and doesn't know that if one is not
set, the other is. By just moving the second test in the else clause
of the assignment both fixes it and makes the code more efficient, and
this can be simplified as a ternary operator.

It's probably not needed to backport this, unless anyone reports build
warnings with more recent compilers (intermediary optimization levels
such as -O1 can sometimes trigger such warnings).

src/http_htx.c

index c9d01aac8db1ff25955ced841858ef06145f38c7..004d3439aac770a231e977bd82238a024fb4c4ee 100644 (file)
@@ -605,22 +605,19 @@ int http_prepend_header_value(struct htx *htx, struct http_hdr_ctx *ctx, const s
        struct htx_blk *blk = ctx->blk;
        struct ist v;
        uint32_t off = 0;
-       uint8_t first = 0;
+       uint8_t first;
 
        if (!blk)
                goto fail;
 
        v = htx_get_blk_value(htx, blk);
 
-       if (!istlen(v)) {
-               start = v.ptr;
-               first = 1;
-       }
+       first = !istlen(v);
+       start = first ? v.ptr : istptr(ctx->value) - ctx->lws_before;
+
        if (unlikely(!istlen(ctx->value)))
                goto fail; /* invalid: value is empty, not supported */
 
-       if (!first)
-               start = istptr(ctx->value) - ctx->lws_before;
        off = start - v.ptr;
 
        blk = htx_replace_blk_value(htx, blk, ist2(start, 0), data);