]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUILD: cfgparse: silence a bogus gcc warning on 32-bit machines
authorWilly Tarreau <w@1wt.eu>
Fri, 24 Jan 2020 10:19:13 +0000 (11:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 24 Jan 2020 10:30:06 +0000 (11:30 +0100)
commit645c588e7138526ccb71f3c47f00045cdf1d8510
tree4df9e9c173772ae128786269b0a0ebd4fc02c1bf
parent541fe1ec52a0f9e1912dea5b3a784406dbdfad22
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 [21474836484294967295] 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