From ad37c7ab257826182c3fb0155d4360833c6ed0f1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 17 Jul 2020 14:18:36 +0200 Subject: [PATCH] BUILD: config: address build warning on raspbian+rpi4 Issue #747 reports that building on raspbian for rpi4 triggers this warning: src/cfgparse.c: In function 'check_config_validity': src/cfgparse.c:3584:26: warning: argument 1 range [2147483648, 4294967295] exceeds maximum object size 2147483647 [-Walloc-size-larger-than=] newsrv->idle_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->idle_conns)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It's surprising because the declared type is size_t and the argument is unsigned (i.e. the same type on 32-bit) precisely to avoid cast issues, but gcc seems to be too smart at this one and to issue a warning over the valid range, implying that passing the originally required type would also warn. Given that these are the only casts in calloc and other ones don't complain, let's drop them. All 3 were added by commit dc2f2753e ("MEDIUM: servers: Split the connections into idle, safe, and available.") that went into 2.2, so this should be backported. --- src/cfgparse.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cfgparse.c b/src/cfgparse.c index f408d65535..9407d89bf4 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -3558,7 +3558,7 @@ out_uri_auth_compat: for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) { int i; - newsrv->available_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->available_conns)); + newsrv->available_conns = calloc(global.nbthread, sizeof(*newsrv->available_conns)); if (!newsrv->available_conns) { ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n", @@ -3590,7 +3590,7 @@ out_uri_auth_compat: } } - newsrv->idle_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->idle_conns)); + newsrv->idle_conns = calloc(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); @@ -3601,7 +3601,7 @@ out_uri_auth_compat: for (i = 0; i < global.nbthread; i++) MT_LIST_INIT(&newsrv->idle_conns[i]); - newsrv->safe_conns = calloc((unsigned)global.nbthread, sizeof(*newsrv->safe_conns)); + newsrv->safe_conns = calloc(global.nbthread, sizeof(*newsrv->safe_conns)); if (!newsrv->safe_conns) { ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n", newsrv->conf.file, newsrv->conf.line, newsrv->id); -- 2.39.5