From: Willy Tarreau Date: Sat, 10 Feb 2024 10:35:07 +0000 (+0100) Subject: BUILD: address a few remaining calloc(size, n) cases X-Git-Tag: v3.0-dev3~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab8928b9dbbae77602b1cd50b0f7189835df9164;p=thirdparty%2Fhaproxy.git BUILD: address a few remaining calloc(size, n) cases In issue #2427 Ilya reports that gcc-14 rightfully complains about sizeof() being placed in the left term of calloc(). There's no impact but it's a bad pattern that gets copy-pasted over time. Let's fix the few remaining occurrences (debug.c, halog, udp-perturb). This can be backported to all branches, and the irrelevant parts dropped. --- diff --git a/admin/halog/halog.c b/admin/halog/halog.c index f2b9dd7e70..884a606e83 100644 --- a/admin/halog/halog.c +++ b/admin/halog/halog.c @@ -410,7 +410,7 @@ struct timer *insert_timer(struct eb_root *r, struct timer **alloc, int v) struct eb32_node *n; if (!t) { - t = calloc(sizeof(*t), 1); + t = calloc(1, sizeof(*t)); if (unlikely(!t)) { fprintf(stderr, "%s: not enough memory\n", __FUNCTION__); exit(1); @@ -438,7 +438,7 @@ struct timer *insert_value(struct eb_root *r, struct timer **alloc, int v) struct eb32_node *n; if (!t) { - t = calloc(sizeof(*t), 1); + t = calloc(1, sizeof(*t)); if (unlikely(!t)) { fprintf(stderr, "%s: not enough memory\n", __FUNCTION__); exit(1); diff --git a/dev/udp/udp-perturb.c b/dev/udp/udp-perturb.c index 8a851fc49c..55d1773438 100644 --- a/dev/udp/udp-perturb.c +++ b/dev/udp/udp-perturb.c @@ -489,7 +489,7 @@ int main(int argc, char **argv) if (addr_to_ss(argv[optind+1], &srv_addr, &err) < 0) die(1, "parsing server address: %s\n", err.msg); - pfd = calloc(sizeof(struct pollfd), MAXCONN + 1); + pfd = calloc(MAXCONN + 1, sizeof(struct pollfd)); if (!pfd) die(1, "out of memory\n"); diff --git a/src/debug.c b/src/debug.c index e69a827436..d1526e1d44 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1293,7 +1293,7 @@ static int debug_parse_delay_inj(char **args, char *payload, struct appctx *appc _HA_ATOMIC_INC(&debug_commands_issued); - tctx = calloc(sizeof(*tctx), 2); + tctx = calloc(2, sizeof(*tctx)); if (!tctx) goto fail; @@ -1427,7 +1427,7 @@ static int debug_parse_cli_sched(char **args, char *payload, struct appctx *appc *(uint8_t *)ptr = new; } - tctx = calloc(sizeof(*tctx), count + 2); + tctx = calloc(count + 2, sizeof(*tctx)); if (!tctx) goto fail;