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. --- src/51d.c | 2 +- src/arg.c | 2 +- src/cfgparse-listen.c | 2 +- src/check.c | 4 ++-- src/extcheck.c | 4 ++-- src/fd.c | 4 ++-- src/haproxy.c | 5 +++-- src/hlua.c | 3 ++- src/lb_chash.c | 3 ++- src/lb_map.c | 2 +- src/ssl_sock.c | 2 +- src/tools.c | 2 +- src/uri_auth.c | 2 +- 13 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/51d.c b/src/51d.c index 52887a934..483a17b4b 100644 --- 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) diff --git a/src/arg.c b/src/arg.c index df5929877..982bab55e 100644 --- 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) { diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 089c177a9..ac23bf65d 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -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; } diff --git a/src/check.c b/src/check.c index c9802a603..4d6b75b10 100644 --- a/src/check.c +++ b/src/check.c @@ -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"; diff --git a/src/extcheck.c b/src/extcheck.c index 721e49d42..e6b30ff9e 100644 --- a/src/extcheck.c +++ b/src/extcheck.c @@ -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; diff --git a/src/fd.c b/src/fd.c index c72dddd82..d05df5875 100644 --- 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; diff --git a/src/haproxy.c b/src/haproxy.c index e70870ab0..588ca1a86 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -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; diff --git a/src/hlua.c b/src/hlua.c index 1eac9d106..491bc9326 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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; diff --git a/src/lb_chash.c b/src/lb_chash.c index 9f7ad5ccd..55417b5e7 100644 --- a/src/lb_chash.c +++ b/src/lb_chash.c @@ -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); diff --git a/src/lb_map.c b/src/lb_map.c index b863d5f78..ef32deb3f 100644 --- a/src/lb_map.c +++ b/src/lb_map.c @@ -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); diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 64c86b116..b8d6b4c54 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -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); diff --git a/src/tools.c b/src/tools.c index b5cc30e68..803afab9e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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; diff --git a/src/uri_auth.c b/src/uri_auth.c index 57dbadbf6..27cb66e45 100644 --- a/src/uri_auth.c +++ b/src/uri_auth.c @@ -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; -- 2.28.0