]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: address a few remaining calloc(size, n) cases
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Feb 2024 10:35:07 +0000 (11:35 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Feb 2024 10:37:27 +0000 (11:37 +0100)
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
dev/udp/udp-perturb.c
src/debug.c

index f2b9dd7e70b61754ae515d19aa30f84371e213c7..884a606e83dae97c8cb60cb22f49b30f28285414 100644 (file)
@@ -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);
index 8a851fc49c344e3158f184f783dfd900291f657a..55d17734388c6a1ac5c05474a52dc4f9c8a9f4a4 100644 (file)
@@ -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");
 
index e69a8274367f37616d6407e6ef967ee035ef6076..d1526e1d44dc17df6c324b3a926cba9de9e4085f 100644 (file)
@@ -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;