From ab8928b9dbbae77602b1cd50b0f7189835df9164 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 10 Feb 2024 11:35:07 +0100 Subject: [PATCH] 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. --- admin/halog/halog.c | 4 ++-- dev/udp/udp-perturb.c | 2 +- src/debug.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/admin/halog/halog.c b/admin/halog/halog.c index f2b9dd7e70b61..884a606e83dae 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 8a851fc49c344..55d17734388c6 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 e69a8274367f3..d1526e1d44dc1 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;