commit eb94d47fbc0abc3c0b29a2f0a2bc666db38e2e87 Author: Willy Tarreau Date: Fri Jan 24 11:19:13 2020 +0100 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. (cherry picked from commit 645c588e7138526ccb71f3c47f00045cdf1d8510) Signed-off-by: Willy Tarreau diff --git a/src/cfgparse.c b/src/cfgparse.c index 7f884df7c..2a22405a3 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3656,7 +3656,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++)