]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: backend: silence a build warning when threads are disabled
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 17:16:14 +0000 (18:16 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 17:16:14 +0000 (18:16 +0100)
Since commit 8de8ed4f48 ("MEDIUM: connections: Allow taking over
connections from other tgroups.") we got this partially absurd
build warning when disabling threads:

  src/backend.c: In function 'conn_backend_get':
  src/backend.c:1371:27: warning: array subscript [0, 0] is outside array bounds of 'struct tgroup_info[1]' [-Warray-bounds]

The reason is that gcc sees that curtgid is not equal to tgid which is
defined as 1 in this case, thus it figures that tgroup_info[curtgid-1]
will be anything but zero and that doesn't fit. It is ridiculous as it
is a perfect case of dead code elimination which should not warrant a
warning. Nevertheless we know we don't need to do this when threads are
disabled and in this case there will not be more than 1 thread group, so
we can happily use that preliminary test to help the compiler eliminate
the dead condition and avoid spitting this warning.

No backport is needed.

src/backend.c

index d8c9df8123af24779f8e31104c5c9e358f044a54..d27baad9dca05425e91ed15edfecb4ef2e4d12b3 100644 (file)
@@ -1367,7 +1367,7 @@ check_tgid:
                if (curtgid == global.nbtgroups + 1)
                        curtgid = 1;
                /* If we haven't looped yet */
-               if (curtgid != tgid) {
+               if (MAX_TGROUPS > 1 && curtgid != tgid) {
                        curtg = &ha_tgroup_info[curtgid - 1];
                        stop = curtg->base;
                        goto check_tgid;