]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: http: silence an uninitialized warning affecting gcc-5
authorWilly Tarreau <w@1wt.eu>
Sun, 10 Jul 2022 11:13:52 +0000 (13:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 10 Jul 2022 12:13:48 +0000 (14:13 +0200)
When building with gcc-5, one can see this warning:

  src/http_fetch.c: In function 'smp_fetch_meth':
  src/http_fetch.c:356:6: warning: 'htx' may be used uninitialized in this function [-Wmaybe-uninitialized]
     sl = http_get_stline(htx);
        ^

It's wrong since the only way to reach this code is to have met the
same condition a few lines before and initialized the htx variable.
The reason in fact is that the same test happens on different variables
of distinct types, so the compiler possibly doesn't know that the
condition is the same. Newer gcc versions do not have this problem.
Let's just move the assignment earlier and have the exact same test,
as it's sufficient to shut this up. This may have to be backported
to 2.6 since the code is the same there.

src/http_fetch.c

index f70fc7f0332c2f103fabc14aa497d58cd2c429d5..ddfb2222d4962a68ceee10033692d9b553c28d49 100644 (file)
@@ -341,13 +341,13 @@ static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char
        if (!txn)
                return 0;
 
-       if (txn->meth == HTTP_METH_OTHER) {
+       meth = txn->meth;
+       if (meth == HTTP_METH_OTHER) {
                htx = smp_prefetch_htx(smp, chn, NULL, 1);
                if (!htx)
                        return 0;
        }
 
-       meth = txn->meth;
        smp->data.type = SMP_T_METH;
        smp->data.u.meth.meth = meth;
        if (meth == HTTP_METH_OTHER) {