From 78ef52dbd1d2432b7ff7b1ed6ebf3b1827cf31ce Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 12 Mar 2025 18:16:14 +0100 Subject: [PATCH] BUILD: backend: silence a build warning when threads are disabled 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index d8c9df812..d27baad9d 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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;