]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: config: fix again bugs gcc warnings on calloc
authorWilly Tarreau <w@1wt.eu>
Fri, 17 Jul 2020 13:04:53 +0000 (15:04 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Jul 2020 13:04:53 +0000 (15:04 +0200)
Since commit ad37c7ab ("BUILD: config: address build warning on
raspbian+rpi4") gcc 7.3.0 complains again on x86_64 (while 8.2.0
does not) :

  src/cfgparse.c: In function 'check_config_validity':
  src/cfgparse.c:3593:26: warning: argument 1 range [1844674407156206796818446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
       newsrv->idle_conns = calloc(global.nbthread, sizeof(*newsrv->idle_conns));
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This thing is completely bogus (actually the RPi one was the most wrong).
Let's try to shut them both by using an unsigned short for the cast which
is expected to satisfy everyone. It's worth noting that the exact same call
a few lines above and below do not trigger this stupid warning.

This should be backported to 2.2 since the fix above was put there already.

src/cfgparse.c

index 9407d89bf438e27eb4cce6ecaa4417bac92abd5b..be36571cd127b9daf22040cb9974d712a2aa1ead 100644 (file)
@@ -3590,7 +3590,7 @@ out_uri_auth_compat:
                                        }
                                }
 
-                               newsrv->idle_conns = calloc(global.nbthread, sizeof(*newsrv->idle_conns));
+                               newsrv->idle_conns = calloc((unsigned short)global.nbthread, sizeof(*newsrv->idle_conns));
                                if (!newsrv->idle_conns) {
                                        ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
                                            newsrv->conf.file, newsrv->conf.line, newsrv->id);