From 645c588e7138526ccb71f3c47f00045cdf1d8510 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 24 Jan 2020 11:19:13 +0100 Subject: [PATCH] BUILD: cfgparse: silence a bogus gcc warning on 32-bit machines A first patch was made during 2.0-dev to silence a bogus warning emitted by gcc : dd1c8f1f72 ("MINOR: cfgparse: Add a cast to make gcc happier."), but it happens it was not sufficient as the warning re-appeared on 32-bit machines under gcc-8 and gcc-9 : src/cfgparse.c: In function 'check_config_validity': src/cfgparse.c:3642:33: warning: argument 1 range [2147483648, 4294967295] exceeds maximum object size 2147483647 [-Walloc-size-larger-than=] newsrv->idle_orphan_conns = calloc((unsigned int)global.nbthread, sizeof(*newsrv->idle_orphan_conns)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This warning doesn't trigger in other locations, and it immediately vanishes if the previous or subsequent loops do not depend on global.nbthread anymore, or if the field ordering of the struct server changes! As discussed in the thread at: https://www.mail-archive.com/haproxy@formilux.org/msg36107.html playing with -Walloc-size-larger-than has no effect. And a minimal reproducer could be isolated, indicating it's pointless to circle around this one. Let's just cast nbthread to ushort so that gcc cannot make this wrong detection. It's unlikely we'll use more than 65535 threads in the near future anyway. This may be backported to older releases if they are also affected, at least to ease the job of distro maintainers. Thanks to Ilya for testing. --- src/cfgparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index 91ca63d6a..cd90d7e80 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3639,7 +3639,7 @@ out_uri_auth_compat: MT_LIST_INIT(&toremove_connections[i]); } } - newsrv->idle_orphan_conns = calloc((unsigned int)global.nbthread, sizeof(*newsrv->idle_orphan_conns)); + newsrv->idle_orphan_conns = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_orphan_conns)); if (!newsrv->idle_orphan_conns) goto err; for (i = 0; i < global.nbthread; i++)