CLEANUP: Do not use a fixed type for 'sizeof' in 'calloc'

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
02779b6263.
This commit is contained in:
Tim Duesterhus 2020-09-12 20:26:43 +02:00 committed by Willy Tarreau
parent b53dd03dc0
commit e52b6e5456
13 changed files with 20 additions and 17 deletions

View File

@ -636,7 +636,7 @@ static int init_51degrees(void)
i = 0; i = 0;
list_for_each_entry(name, &global_51degrees.property_names, list) list_for_each_entry(name, &global_51degrees.property_names, list)
++i; ++i;
_51d_property_list = calloc(i, sizeof(char *)); _51d_property_list = calloc(i, sizeof(*_51d_property_list));
i = 0; i = 0;
list_for_each_entry(name, &global_51degrees.property_names, list) list_for_each_entry(name, &global_51degrees.property_names, list)

View File

@ -147,7 +147,7 @@ int make_arg_list(const char *in, int len, uint64_t mask, struct arg **argp,
if (empty && !min_arg) if (empty && !min_arg)
goto end_parse; 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. */ /* Note: empty arguments after a comma always exist. */
while (pos < nbarg) { while (pos < nbarg) {

View File

@ -442,7 +442,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
/* default compression options */ /* default compression options */
if (defproxy.comp != NULL) { 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->algos = defproxy.comp->algos;
curproxy->comp->types = defproxy.comp->types; curproxy->comp->types = defproxy.comp->types;
} }

View 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->bi); check->bi.size = global.tune.chksize;
b_reset(&check->bo); check->bo.size = global.tune.chksize; b_reset(&check->bo); check->bo.size = global.tune.chksize;
check->bi.area = calloc(check->bi.size, sizeof(char)); check->bi.area = calloc(check->bi.size, sizeof(*check->bi.area));
check->bo.area = calloc(check->bo.size, sizeof(char)); check->bo.area = calloc(check->bo.size, sizeof(*check->bo.area));
if (!check->bi.area || !check->bo.area) if (!check->bi.area || !check->bo.area)
return "out of memory while allocating check buffer"; return "out of memory while allocating check buffer";

View File

@ -274,13 +274,13 @@ int prepare_external_check(struct check *check)
} }
check->curpid = NULL; check->curpid = NULL;
check->envp = calloc((EXTCHK_SIZE + 1), sizeof(char *)); check->envp = calloc((EXTCHK_SIZE + 1), sizeof(*check->envp));
if (!check->envp) { if (!check->envp) {
ha_alert("Failed to allocate memory for environment variables. Aborting\n"); ha_alert("Failed to allocate memory for environment variables. Aborting\n");
goto err; goto err;
} }
check->argv = calloc(6, sizeof(char *)); check->argv = calloc(6, sizeof(*check->argv));
if (!check->argv) { if (!check->argv) {
ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id); ha_alert("Starting [%s:%s] check: out of memory.\n", px->id, s->id);
goto err; goto err;

View File

@ -655,13 +655,13 @@ int init_pollers()
int p; int p;
struct poller *bp; struct poller *bp;
if ((fdtab = calloc(global.maxsock, sizeof(struct fdtab))) == NULL) if ((fdtab = calloc(global.maxsock, sizeof(*fdtab))) == NULL)
goto fail_tab; goto fail_tab;
if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL) if ((polled_mask = calloc(global.maxsock, sizeof(*polled_mask))) == NULL)
goto fail_polledmask; goto fail_polledmask;
if ((fdinfo = calloc(global.maxsock, sizeof(struct fdinfo))) == NULL) if ((fdinfo = calloc(global.maxsock, sizeof(*fdinfo))) == NULL)
goto fail_info; goto fail_info;
update_list.first = update_list.last = -1; update_list.first = update_list.last = -1;

View File

@ -799,7 +799,8 @@ void mworker_reload()
old_argc++; old_argc++;
/* 1 for haproxy -sf, 2 for -x /socket */ /* 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) if (next_argv == NULL)
goto alloc_error; goto alloc_error;
@ -1133,7 +1134,7 @@ static char **copy_argv(int argc, char **argv)
{ {
char **newargv, **retargv; char **newargv, **retargv;
newargv = calloc(argc + 2, sizeof(char *)); newargv = calloc(argc + 2, sizeof(*newargv));
if (newargv == NULL) { if (newargv == NULL) {
ha_warning("Cannot allocate memory\n"); ha_warning("Cannot allocate memory\n");
return NULL; return NULL;

View File

@ -7362,7 +7362,8 @@ static enum act_parse_ret action_register_lua(const char **args, int *cur_arg, s
} }
/* Memory for arguments. */ /* 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) { if (!rule->arg.hlua_rule->args) {
memprintf(err, "out of memory error"); memprintf(err, "out of memory error");
return ACT_RET_PRS_ERR; return ACT_RET_PRS_ERR;

View 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_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_tot = srv->uweight * BE_WEIGHT_SCALE;
srv->lb_nodes_now = 0; 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++) { for (node = 0; node < srv->lb_nodes_tot; node++) {
srv->lb_nodes[node].server = srv; srv->lb_nodes[node].server = srv;
srv->lb_nodes[node].node.key = full_hash(srv->puid * SRV_EWGHT_RANGE + node); srv->lb_nodes[node].node.key = full_hash(srv->puid * SRV_EWGHT_RANGE + node);

View File

@ -196,7 +196,7 @@ void init_server_map(struct proxy *p)
if (!act) if (!act)
act = 1; 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 */ /* recounts servers and their weights */
recount_servers(p); recount_servers(p);
update_backend_weight(p); update_backend_weight(p);

View File

@ -5107,7 +5107,7 @@ ssl_sock_load_ca(struct bind_conf *bind_conf)
} }
/* Allocate cert structure */ /* Allocate cert structure */
ckch = calloc(1, sizeof(struct cert_key_and_chain)); ckch = calloc(1, sizeof(*ckch));
if (!ckch) { if (!ckch) {
ha_alert("Proxy '%s': Failed to read CA certificate file '%s' at [%s:%d]. Chain allocation failure\n", 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); px->id, bind_conf->ca_sign_file, bind_conf->file, bind_conf->line);

View File

@ -2236,7 +2236,7 @@ int parse_binary(const char *source, char **binstr, int *binstrlen, char **err)
len = len >> 1; len = len >> 1;
if (!*binstr) { if (!*binstr) {
*binstr = calloc(len, sizeof(char)); *binstr = calloc(len, sizeof(**binstr));
if (!*binstr) { if (!*binstr) {
memprintf(err, "out of memory while loading string pattern"); memprintf(err, "out of memory while loading string pattern");
return 0; return 0;

View File

@ -226,7 +226,7 @@ struct uri_auth *stats_add_auth(struct uri_auth **root, char *user)
return NULL; return NULL;
if (!u->userlist) if (!u->userlist)
u->userlist = calloc(1, sizeof(struct userlist)); u->userlist = calloc(1, sizeof(*u->userlist));
if (!u->userlist) if (!u->userlist)
return NULL; return NULL;