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
02779b6263a177b1e462e53db6eaf57bcda574bc.
diff --git a/src/51d.c b/src/51d.c
index 52887a9..483a17b 100644
--- a/src/51d.c
+++ b/src/51d.c
@@ -636,7 +636,7 @@
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 df59298..982bab5 100644
--- a/src/arg.c
+++ b/src/arg.c
@@ -147,7 +147,7 @@
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 089c177..ac23bf6 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -442,7 +442,7 @@
/* 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 c9802a6..4d6b75b 100644
--- a/src/check.c
+++ b/src/check.c
@@ -968,8 +968,8 @@
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 721e49d..e6b30ff 100644
--- a/src/extcheck.c
+++ b/src/extcheck.c
@@ -274,13 +274,13 @@
}
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 c72dddd..d05df58 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -655,13 +655,13 @@
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 e70870a..588ca1a 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -799,7 +799,8 @@
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 @@
{
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 1eac9d1..491bc93 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -7362,7 +7362,8 @@
}
/* 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 9f7ad5c..55417b5 100644
--- a/src/lb_chash.c
+++ b/src/lb_chash.c
@@ -493,7 +493,8 @@
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 b863d5f..ef32deb 100644
--- a/src/lb_map.c
+++ b/src/lb_map.c
@@ -196,7 +196,7 @@
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 64c86b1..b8d6b4c 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -5107,7 +5107,7 @@
}
/* 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 b5cc30e..803afab 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -2236,7 +2236,7 @@
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 57dbadb..27cb66e 100644
--- a/src/uri_auth.c
+++ b/src/uri_auth.c
@@ -226,7 +226,7 @@
return NULL;
if (!u->userlist)
- u->userlist = calloc(1, sizeof(struct userlist));
+ u->userlist = calloc(1, sizeof(*u->userlist));
if (!u->userlist)
return NULL;