From db812f73afdda225d7ddd1f887e08ce042e273dc Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 1 Dec 2023 15:29:44 +0100 Subject: [PATCH] BUILD: http_htx: silence uninitialized warning on some gcc versions 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 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/http_htx.c b/src/http_htx.c index c9d01aac8..004d3439a 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -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);