]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: Do not use a fixed type for 'sizeof' in 'calloc'
authorTim Duesterhus <tim@bastelstu.be>
Sat, 12 Sep 2020 18:26:43 +0000 (20:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 12 Sep 2020 18:31:25 +0000 (20:31 +0200)
Changes performed using the following coccinelle patch:

    @@
    type T;
    expression E;
    expression t;
    @@

    (
      t = calloc(E, sizeof(*t))
    |
    - t = calloc(E, sizeof(T))
    + t = calloc(E, sizeof(*t))
    )

Looking through the commit history, grepping for coccinelle shows that the same
replacement with a different patch was already performed in the past in commit
02779b6263a177b1e462e53db6eaf57bcda574bc.

13 files changed:
src/51d.c
src/arg.c
src/cfgparse-listen.c
src/check.c
src/extcheck.c
src/fd.c
src/haproxy.c
src/hlua.c
src/lb_chash.c
src/lb_map.c
src/ssl_sock.c
src/tools.c
src/uri_auth.c

index 52887a934016ae965ec46aeaf5fe5cde3df52c61..483a17b4ba66f9fc999f5a1540be5948563099c8 100644 (file)
--- a/src/51d.c
+++ b/src/51d.c
@@ -636,7 +636,7 @@ static int init_51degrees(void)
                i = 0;
                list_for_each_entry(name, &global_51degrees.property_names, list)
                        ++i;
-               _51d_property_list = calloc(i, sizeof(char *));
+               _51d_property_list = calloc(i, sizeof(*_51d_property_list));
 
                i = 0;
                list_for_each_entry(name, &global_51degrees.property_names, list)
index df5929877d8b594317af040d2f4236fc11ca8a92..982bab55eac0b179c0609da1be3366f6674f0697 100644 (file)
--- a/src/arg.c
+++ b/src/arg.c
@@ -147,7 +147,7 @@ int make_arg_list(const char *in, int len, uint64_t mask, struct arg **argp,
        if (empty && !min_arg)
                goto end_parse;
 
-       arg = *argp = calloc(nbarg + 1, sizeof(*arg));
+       arg = *argp = calloc(nbarg + 1, sizeof(**argp));
 
        /* Note: empty arguments after a comma always exist. */
        while (pos < nbarg) {
index 089c177a9fb7af9a521c8a40558a649b11711c27..ac23bf65dd5afccb5e382082a14906e77d8be492 100644 (file)
@@ -442,7 +442,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                /* default compression options */
                if (defproxy.comp != NULL) {
-                       curproxy->comp = calloc(1, sizeof(struct comp));
+                       curproxy->comp = calloc(1, sizeof(*curproxy->comp));
                        curproxy->comp->algos = defproxy.comp->algos;
                        curproxy->comp->types = defproxy.comp->types;
                }
index c9802a603965ee45e20cf7d024937301995f8c83..4d6b75b107e7d521b3092bdb112217de4605bd33 100644 (file)
@@ -968,8 +968,8 @@ const char *init_check(struct check *check, int type)
        b_reset(&check->bi); check->bi.size = global.tune.chksize;
        b_reset(&check->bo); check->bo.size = global.tune.chksize;
 
-       check->bi.area = calloc(check->bi.size, sizeof(char));
-       check->bo.area = calloc(check->bo.size, sizeof(char));
+       check->bi.area = calloc(check->bi.size, sizeof(*check->bi.area));
+       check->bo.area = calloc(check->bo.size, sizeof(*check->bo.area));
 
        if (!check->bi.area || !check->bo.area)
                return "out of memory while allocating check buffer";
index 721e49d42cd9ad62d22b31ee222c20798b2b3d04..e6b30ff9e528e6dc58de65e3ae562ca6887321a2 100644 (file)
@@ -274,13 +274,13 @@ int prepare_external_check(struct check *check)
                }
 
        check->curpid = NULL;
-       check->envp = calloc((EXTCHK_SIZE + 1), sizeof(char *));
+       check->envp = calloc((EXTCHK_SIZE + 1), sizeof(*check->envp));
        if (!check->envp) {
                ha_alert("Failed to allocate memory for environment variables. Aborting\n");
                goto err;
        }
 
-       check->argv = calloc(6, sizeof(char *));
+       check->argv = calloc(6, sizeof(*check->argv));
        if (!check->argv) {
                ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
                goto err;
index c72dddd823516df19b04f7cff55d36f5cdf1f33a..d05df58752b5cce1144869f3eb93cd93940c5e03 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -655,13 +655,13 @@ int init_pollers()
        int p;
        struct poller *bp;
 
-       if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL)
+       if ((fdtab = calloc(global.maxsock, sizeof(*fdtab))) == NULL)
                goto fail_tab;
 
        if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL)
                goto fail_polledmask;
 
-       if ((fdinfo = calloc(global.maxsock, sizeof(struct fdinfo))) == NULL)
+       if ((fdinfo = calloc(global.maxsock, sizeof(*fdinfo))) == NULL)
                goto fail_info;
 
        update_list.first = update_list.last = -1;
index e70870ab04665c12da28a536e22fbd5a6cdb6194..588ca1a86c07d04e2175208c628a1bc7a980624a 100644 (file)
@@ -799,7 +799,8 @@ void mworker_reload()
                old_argc++;
 
        /* 1 for haproxy -sf, 2 for -x /socket */
-       next_argv = calloc(old_argc + 1 + 2 + mworker_child_nb() + nb_oldpids + 1, sizeof(char *));
+       next_argv = calloc(old_argc + 1 + 2 + mworker_child_nb() + nb_oldpids + 1,
+                          sizeof(*next_argv));
        if (next_argv == NULL)
                goto alloc_error;
 
@@ -1133,7 +1134,7 @@ static char **copy_argv(int argc, char **argv)
 {
        char **newargv, **retargv;
 
-       newargv = calloc(argc + 2, sizeof(char *));
+       newargv = calloc(argc + 2, sizeof(*newargv));
        if (newargv == NULL) {
                ha_warning("Cannot allocate memory\n");
                return NULL;
index 1eac9d10678ab503993a9c9e82d183061821955a..491bc93260c9eb270023c66d964de314f8d71035 100644 (file)
@@ -7362,7 +7362,8 @@ static enum act_parse_ret action_register_lua(const char **args, int *cur_arg, s
        }
 
        /* Memory for arguments. */
-       rule->arg.hlua_rule->args = calloc(fcn->nargs + 1, sizeof(char *));
+       rule->arg.hlua_rule->args = calloc(fcn->nargs + 1,
+                                          sizeof(*rule->arg.hlua_rule->args));
        if (!rule->arg.hlua_rule->args) {
                memprintf(err, "out of memory error");
                return ACT_RET_PRS_ERR;
index 9f7ad5ccddfd0093270cf2f70eeff76e8a46d564..55417b5e73e21d5dd66bddedfa57aee98218ccdd 100644 (file)
@@ -493,7 +493,8 @@ void chash_init_server_tree(struct proxy *p)
                srv->lb_tree = (srv->flags & SRV_F_BACKUP) ? &p->lbprm.chash.bck : &p->lbprm.chash.act;
                srv->lb_nodes_tot = srv->uweight * BE_WEIGHT_SCALE;
                srv->lb_nodes_now = 0;
-               srv->lb_nodes = calloc(srv->lb_nodes_tot, sizeof(struct tree_occ));
+               srv->lb_nodes = calloc(srv->lb_nodes_tot,
+                                      sizeof(*srv->lb_nodes));
                for (node = 0; node < srv->lb_nodes_tot; node++) {
                        srv->lb_nodes[node].server = srv;
                        srv->lb_nodes[node].node.key = full_hash(srv->puid * SRV_EWGHT_RANGE + node);
index b863d5f781c535a1333674003763aeba26f0b07d..ef32deb3fdbe5a2203607042bf2d7aedd73a1673 100644 (file)
@@ -196,7 +196,7 @@ void init_server_map(struct proxy *p)
        if (!act)
                act = 1;
 
-       p->lbprm.map.srv = calloc(act, sizeof(struct server *));
+       p->lbprm.map.srv = calloc(act, sizeof(*p->lbprm.map.srv));
        /* recounts servers and their weights */
        recount_servers(p);
        update_backend_weight(p);
index 64c86b11686a423b20ead0bce5da5bd250d8799d..b8d6b4c5484e0bf5440155dd7d74491d922dbbdf 100644 (file)
@@ -5107,7 +5107,7 @@ ssl_sock_load_ca(struct bind_conf *bind_conf)
        }
 
        /* Allocate cert structure */
-       ckch = calloc(1, sizeof(struct cert_key_and_chain));
+       ckch = calloc(1, sizeof(*ckch));
        if (!ckch) {
                ha_alert("Proxy '%s': Failed to read CA certificate file '%s' at [%s:%d]. Chain allocation failure\n",
                        px->id, bind_conf->ca_sign_file, bind_conf->file, bind_conf->line);
index b5cc30e68d55c5ce854adadb1a4304f122fe9f5f..803afab9e9f30ca3258cdd0a4742d2510d008d6a 100644 (file)
@@ -2236,7 +2236,7 @@ int parse_binary(const char *source, char **binstr, int *binstrlen, char **err)
        len = len >> 1;
 
        if (!*binstr) {
-               *binstr = calloc(len, sizeof(char));
+               *binstr = calloc(len, sizeof(**binstr));
                if (!*binstr) {
                        memprintf(err, "out of memory while loading string pattern");
                        return 0;
index 57dbadbf64173647e86e2baed91da7c14046c258..27cb66e45b87152969e799a8df0bc2dea4891db0 100644 (file)
@@ -226,7 +226,7 @@ struct uri_auth *stats_add_auth(struct uri_auth **root, char *user)
                return NULL;
 
        if (!u->userlist)
-               u->userlist = calloc(1, sizeof(struct userlist));
+               u->userlist = calloc(1, sizeof(*u->userlist));
 
        if (!u->userlist)
                return NULL;