mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
CLEANUP: uniformize last argument of malloc/calloc
Instead of repeating the type of the LHS argument (sizeof(struct ...)) in calls to malloc/calloc, we directly use the pointer name (sizeof(*...)). The following Coccinelle patch was used: @@ type T; T *x; @@ x = malloc( - sizeof(T) + sizeof(*x) ) @@ type T; T *x; @@ x = calloc(1, - sizeof(T) + sizeof(*x) ) When the LHS is not just a variable name, no change is made. Moreover, the following patch was used to ensure that "1" is consistently used as a first argument of calloc, not the last one: @@ @@ calloc( + 1, ... - ,1 )
This commit is contained in:
parent
3c2f2f207f
commit
02779b6263
@ -54,7 +54,7 @@ static int _51d_property_name_list(char **args, int section_type, struct proxy *
|
||||
}
|
||||
|
||||
while (*(args[cur_arg])) {
|
||||
name = calloc(1, sizeof(struct _51d_property_names));
|
||||
name = calloc(1, sizeof(*name));
|
||||
name->name = strdup(args[cur_arg]);
|
||||
LIST_ADDQ(&global._51degrees.property_names, &name->list);
|
||||
++cur_arg;
|
||||
@ -158,7 +158,7 @@ static void *_51d_malloc(int size)
|
||||
*/
|
||||
static void _51d_insert_cache_entry(struct sample *smp, struct lru64 *lru, void* domain)
|
||||
{
|
||||
struct chunk *cache_entry = _51d_malloc(sizeof(struct chunk));
|
||||
struct chunk *cache_entry = _51d_malloc(sizeof(*cache_entry));
|
||||
|
||||
if (!cache_entry)
|
||||
return;
|
||||
|
@ -176,7 +176,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
|
||||
/* OK we have a real ACL keyword */
|
||||
|
||||
/* build new sample expression for this ACL */
|
||||
smp = calloc(1, sizeof(struct sample_expr));
|
||||
smp = calloc(1, sizeof(*smp));
|
||||
if (!smp) {
|
||||
memprintf(err, "out of memory when parsing ACL expression");
|
||||
goto out_return;
|
||||
@ -298,7 +298,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
|
||||
}
|
||||
|
||||
cur_type = conv->out_type;
|
||||
conv_expr = calloc(1, sizeof(struct sample_conv_expr));
|
||||
conv_expr = calloc(1, sizeof(*conv_expr));
|
||||
if (!conv_expr)
|
||||
goto out_free_smp;
|
||||
|
||||
|
@ -290,7 +290,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf,
|
||||
ss = *ss2;
|
||||
|
||||
for (; port <= end; port++) {
|
||||
l = calloc(1, sizeof(struct listener));
|
||||
l = calloc(1, sizeof(*l));
|
||||
l->obj_type = OBJ_TYPE_LISTENER;
|
||||
LIST_ADDQ(&curproxy->conf.listeners, &l->by_fe);
|
||||
LIST_ADDQ(&bind_conf->listeners, &l->by_bind);
|
||||
@ -1571,7 +1571,7 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
logsrv = calloc(1, sizeof(struct logsrv));
|
||||
logsrv = calloc(1, sizeof(*logsrv));
|
||||
|
||||
/* just after the address, a length may be specified */
|
||||
if (strcmp(args[arg+2], "len") == 0) {
|
||||
@ -2119,7 +2119,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
}
|
||||
|
||||
if ((curpeers = calloc(1, sizeof(struct peers))) == NULL) {
|
||||
if ((curpeers = calloc(1, sizeof(*curpeers))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2153,7 +2153,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((newpeer = calloc(1, sizeof(struct peer))) == NULL) {
|
||||
if ((newpeer = calloc(1, sizeof(*newpeer))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2316,7 +2316,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
}
|
||||
|
||||
if ((curr_resolvers = calloc(1, sizeof(struct dns_resolvers))) == NULL) {
|
||||
if ((curr_resolvers = calloc(1, sizeof(*curr_resolvers))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2364,7 +2364,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
}
|
||||
|
||||
if ((newnameserver = calloc(1, sizeof(struct dns_nameserver))) == NULL) {
|
||||
if ((newnameserver = calloc(1, sizeof(*newnameserver))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2535,7 +2535,7 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
|
||||
}
|
||||
}
|
||||
|
||||
if ((curmailers = calloc(1, sizeof(struct mailers))) == NULL) {
|
||||
if ((curmailers = calloc(1, sizeof(*curmailers))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2570,7 +2570,7 @@ int cfg_parse_mailers(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((newmailer = calloc(1, sizeof(struct mailer))) == NULL) {
|
||||
if ((newmailer = calloc(1, sizeof(*newmailer))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2725,7 +2725,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
}
|
||||
|
||||
if ((curproxy = calloc(1, sizeof(struct proxy))) == NULL) {
|
||||
if ((curproxy = calloc(1, sizeof(*curproxy))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -2911,7 +2911,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
|
||||
/* copy default logsrvs to curproxy */
|
||||
list_for_each_entry(tmplogsrv, &defproxy.logsrvs, list) {
|
||||
struct logsrv *node = malloc(sizeof(struct logsrv));
|
||||
struct logsrv *node = malloc(sizeof(*node));
|
||||
memcpy(node, tmplogsrv, sizeof(struct logsrv));
|
||||
LIST_INIT(&node->list);
|
||||
LIST_ADDQ(&curproxy->logsrvs, &node->list);
|
||||
@ -3739,7 +3739,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
hdr = calloc(sizeof(struct cap_hdr), 1);
|
||||
hdr = calloc(1, sizeof(*hdr));
|
||||
hdr->next = curproxy->req_cap;
|
||||
hdr->name = strdup(args[3]);
|
||||
hdr->namelen = strlen(args[3]);
|
||||
@ -3767,7 +3767,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
||||
err_code |= ERR_ALERT | ERR_FATAL;
|
||||
goto out;
|
||||
}
|
||||
hdr = calloc(sizeof(struct cap_hdr), 1);
|
||||
hdr = calloc(1, sizeof(*hdr));
|
||||
hdr->next = curproxy->rsp_cap;
|
||||
hdr->name = strdup(args[3]);
|
||||
hdr->namelen = strlen(args[3]);
|
||||
@ -6043,7 +6043,7 @@ stats_error_parsing:
|
||||
if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
|
||||
/* copy global.logrsvs linked list to the end of curproxy->logsrvs */
|
||||
list_for_each_entry(tmplogsrv, &global.logsrvs, list) {
|
||||
struct logsrv *node = malloc(sizeof(struct logsrv));
|
||||
struct logsrv *node = malloc(sizeof(*node));
|
||||
memcpy(node, tmplogsrv, sizeof(struct logsrv));
|
||||
LIST_INIT(&node->list);
|
||||
LIST_ADDQ(&curproxy->logsrvs, &node->list);
|
||||
@ -6055,7 +6055,7 @@ stats_error_parsing:
|
||||
int arg = 0;
|
||||
int len = 0;
|
||||
|
||||
logsrv = calloc(1, sizeof(struct logsrv));
|
||||
logsrv = calloc(1, sizeof(*logsrv));
|
||||
|
||||
/* just after the address, a length may be specified */
|
||||
if (strcmp(args[arg+2], "len") == 0) {
|
||||
@ -6782,7 +6782,7 @@ cfg_parse_users(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
newul = calloc(1, sizeof(struct userlist));
|
||||
newul = calloc(1, sizeof(*newul));
|
||||
if (!newul) {
|
||||
Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
@ -6883,7 +6883,7 @@ cfg_parse_users(const char *file, int linenum, char **args, int kwm)
|
||||
goto out;
|
||||
}
|
||||
|
||||
newuser = calloc(1, sizeof(struct auth_users));
|
||||
newuser = calloc(1, sizeof(*newuser));
|
||||
if (!newuser) {
|
||||
Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
|
@ -109,7 +109,7 @@ int comp_append_type(struct comp *comp, const char *type)
|
||||
{
|
||||
struct comp_type *comp_type;
|
||||
|
||||
comp_type = calloc(1, sizeof(struct comp_type));
|
||||
comp_type = calloc(1, sizeof(*comp_type));
|
||||
comp_type->name_len = strlen(type);
|
||||
comp_type->name = strdup(type);
|
||||
comp_type->next = comp->types;
|
||||
@ -127,7 +127,7 @@ int comp_append_algo(struct comp *comp, const char *algo)
|
||||
|
||||
for (i = 0; comp_algos[i].cfg_name; i++) {
|
||||
if (!strcmp(algo, comp_algos[i].cfg_name)) {
|
||||
comp_algo = calloc(1, sizeof(struct comp_algo));
|
||||
comp_algo = calloc(1, sizeof(*comp_algo));
|
||||
memmove(comp_algo, &comp_algos[i], sizeof(struct comp_algo));
|
||||
comp_algo->next = comp->algos;
|
||||
comp->algos = comp_algo;
|
||||
|
@ -909,7 +909,7 @@ int dns_init_resolvers(void)
|
||||
curr_resolvers->t = t;
|
||||
|
||||
list_for_each_entry(curnameserver, &curr_resolvers->nameserver_list, list) {
|
||||
if ((dgram = calloc(1, sizeof(struct dgram_conn))) == NULL) {
|
||||
if ((dgram = calloc(1, sizeof(*dgram))) == NULL) {
|
||||
Alert("Starting [%s/%s] nameserver: out of memory.\n", curr_resolvers->id,
|
||||
curnameserver->id);
|
||||
return 0;
|
||||
|
@ -413,7 +413,7 @@ static struct proxy *alloc_stats_fe(const char *name, const char *file, int line
|
||||
{
|
||||
struct proxy *fe;
|
||||
|
||||
fe = calloc(1, sizeof(struct proxy));
|
||||
fe = calloc(1, sizeof(*fe));
|
||||
if (!fe)
|
||||
return NULL;
|
||||
|
||||
|
@ -772,7 +772,7 @@ parse_compression_options(char **args, int section, struct proxy *proxy,
|
||||
struct comp *comp;
|
||||
|
||||
if (proxy->comp == NULL) {
|
||||
comp = calloc(1, sizeof(struct comp));
|
||||
comp = calloc(1, sizeof(*comp));
|
||||
proxy->comp = comp;
|
||||
}
|
||||
else
|
||||
|
10
src/log.c
10
src/log.c
@ -339,7 +339,7 @@ int parse_logformat_var(char *arg, int arg_len, char *var, int var_len, struct p
|
||||
if (strlen(logformat_keywords[j].name) == var_len &&
|
||||
strncmp(var, logformat_keywords[j].name, var_len) == 0) {
|
||||
if (logformat_keywords[j].mode != PR_MODE_HTTP || curproxy->mode == PR_MODE_HTTP) {
|
||||
node = calloc(1, sizeof(struct logformat_node));
|
||||
node = calloc(1, sizeof(*node));
|
||||
node->type = logformat_keywords[j].type;
|
||||
node->options = *defoptions;
|
||||
if (arg_len) {
|
||||
@ -396,15 +396,15 @@ void add_to_logformat_list(char *start, char *end, int type, struct list *list_f
|
||||
char *str;
|
||||
|
||||
if (type == LF_TEXT) { /* type text */
|
||||
struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
|
||||
str = calloc(end - start + 1, 1);
|
||||
struct logformat_node *node = calloc(1, sizeof(*node));
|
||||
str = calloc(1, end - start + 1);
|
||||
strncpy(str, start, end - start);
|
||||
str[end - start] = '\0';
|
||||
node->arg = str;
|
||||
node->type = LOG_FMT_TEXT; // type string
|
||||
LIST_ADDQ(list_format, &node->list);
|
||||
} else if (type == LF_SEPARATOR) {
|
||||
struct logformat_node *node = calloc(1, sizeof(struct logformat_node));
|
||||
struct logformat_node *node = calloc(1, sizeof(*node));
|
||||
node->type = LOG_FMT_SEPARATOR;
|
||||
LIST_ADDQ(list_format, &node->list);
|
||||
}
|
||||
@ -435,7 +435,7 @@ void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct pro
|
||||
return;
|
||||
}
|
||||
|
||||
node = calloc(1, sizeof(struct logformat_node));
|
||||
node = calloc(1, sizeof(*node));
|
||||
node->type = LOG_FMT_EXPR;
|
||||
node->expr = expr;
|
||||
node->options = options;
|
||||
|
@ -67,7 +67,7 @@ struct netns_entry* netns_store_insert(const char *ns_name)
|
||||
if (fd == -1)
|
||||
goto out;
|
||||
|
||||
entry = calloc(1, sizeof(struct netns_entry));
|
||||
entry = calloc(1, sizeof(*entry));
|
||||
if (!entry)
|
||||
goto out;
|
||||
entry->fd = fd;
|
||||
|
@ -1975,7 +1975,7 @@ void peers_register_table(struct peers *peers, struct stktable *table)
|
||||
int id = 0;
|
||||
|
||||
for (curpeer = peers->remote; curpeer; curpeer = curpeer->next) {
|
||||
st = calloc(1,sizeof(struct shared_table));
|
||||
st = calloc(1,sizeof(*st));
|
||||
st->table = table;
|
||||
st->next = curpeer->tables;
|
||||
if (curpeer->tables)
|
||||
|
@ -8785,7 +8785,7 @@ struct act_rule *parse_http_req_cond(const char **args, const char *file, int li
|
||||
int cur_arg;
|
||||
char *error;
|
||||
|
||||
rule = calloc(1, sizeof(struct act_rule));
|
||||
rule = calloc(1, sizeof(*rule));
|
||||
if (!rule) {
|
||||
Alert("parsing [%s:%d]: out of memory.\n", file, linenum);
|
||||
goto out_err;
|
||||
@ -12421,7 +12421,7 @@ enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, stru
|
||||
return ACT_RET_PRS_ERR;
|
||||
}
|
||||
|
||||
hdr = calloc(sizeof(struct cap_hdr), 1);
|
||||
hdr = calloc(1, sizeof(*hdr));
|
||||
hdr->next = px->req_cap;
|
||||
hdr->name = NULL; /* not a header capture */
|
||||
hdr->namelen = 0;
|
||||
|
@ -1641,7 +1641,7 @@ static int tcp_parse_request_rule(char **args, int arg, int section_type,
|
||||
return -1;
|
||||
}
|
||||
|
||||
hdr = calloc(sizeof(struct cap_hdr), 1);
|
||||
hdr = calloc(1, sizeof(*hdr));
|
||||
hdr->next = curpx->req_cap;
|
||||
hdr->name = NULL; /* not a header capture */
|
||||
hdr->namelen = 0;
|
||||
|
@ -415,7 +415,7 @@ static int proxy_parse_declare(char **args, int section, struct proxy *curpx,
|
||||
}
|
||||
|
||||
/* register the capture. */
|
||||
hdr = calloc(1, sizeof(struct cap_hdr));
|
||||
hdr = calloc(1, sizeof(*hdr));
|
||||
hdr->name = NULL; /* not a header capture */
|
||||
hdr->namelen = 0;
|
||||
hdr->len = len;
|
||||
|
@ -139,7 +139,7 @@ const char *chain_regex(struct hdr_exp **head, struct my_regex *preg,
|
||||
while (*head != NULL)
|
||||
head = &(*head)->next;
|
||||
|
||||
exp = calloc(1, sizeof(struct hdr_exp));
|
||||
exp = calloc(1, sizeof(*exp));
|
||||
|
||||
exp->preg = preg;
|
||||
exp->replace = replace;
|
||||
|
@ -855,7 +855,7 @@ struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, in
|
||||
}
|
||||
prev_type = fetch->out_type;
|
||||
|
||||
expr = calloc(1, sizeof(struct sample_expr));
|
||||
expr = calloc(1, sizeof(*expr));
|
||||
if (!expr)
|
||||
goto out_error;
|
||||
|
||||
@ -958,7 +958,7 @@ struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, in
|
||||
}
|
||||
|
||||
prev_type = conv->out_type;
|
||||
conv_expr = calloc(1, sizeof(struct sample_conv_expr));
|
||||
conv_expr = calloc(1, sizeof(*conv_expr));
|
||||
if (!conv_expr)
|
||||
goto out_error;
|
||||
|
||||
|
@ -874,7 +874,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
|
||||
struct protocol *proto;
|
||||
struct dns_resolution *curr_resolution;
|
||||
|
||||
if ((newsrv = calloc(1, sizeof(struct server))) == NULL) {
|
||||
if ((newsrv = calloc(1, sizeof(*newsrv))) == NULL) {
|
||||
Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
|
||||
err_code |= ERR_ALERT | ERR_ABORT;
|
||||
goto out;
|
||||
@ -945,7 +945,7 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
|
||||
goto skip_name_resolution;
|
||||
|
||||
fqdn = NULL;
|
||||
if ((curr_resolution = calloc(1, sizeof(struct dns_resolution))) == NULL)
|
||||
if ((curr_resolution = calloc(1, sizeof(*curr_resolution))) == NULL)
|
||||
goto skip_name_resolution;
|
||||
|
||||
curr_resolution->hostname_dn_len = dns_str_to_dn_label_len(newsrv->hostname);
|
||||
|
@ -742,7 +742,7 @@ static int ssl_sock_load_ocsp(SSL_CTX *ctx, const char *cert_path)
|
||||
if (!i || (i > OCSP_MAX_CERTID_ASN1_LENGTH))
|
||||
goto out;
|
||||
|
||||
ocsp = calloc(1, sizeof(struct certificate_ocsp));
|
||||
ocsp = calloc(1, sizeof(*ocsp));
|
||||
if (!ocsp)
|
||||
goto out;
|
||||
|
||||
@ -754,7 +754,7 @@ static int ssl_sock_load_ocsp(SSL_CTX *ctx, const char *cert_path)
|
||||
ocsp = NULL;
|
||||
|
||||
if (!ctx->tlsext_status_cb) {
|
||||
struct ocsp_cbk_arg *cb_arg = calloc(1, sizeof(struct ocsp_cbk_arg));
|
||||
struct ocsp_cbk_arg *cb_arg = calloc(1, sizeof(*cb_arg));
|
||||
|
||||
cb_arg->is_single = 1;
|
||||
cb_arg->s_ocsp = iocsp;
|
||||
@ -897,7 +897,7 @@ static int ssl_sock_load_sctl_from_file(const char *sctl_path, struct chunk **sc
|
||||
if (ret)
|
||||
goto end;
|
||||
|
||||
*sctl = calloc(1, sizeof(struct chunk));
|
||||
*sctl = calloc(1, sizeof(**sctl));
|
||||
if (!chunk_dup(*sctl, &trash)) {
|
||||
free(*sctl);
|
||||
*sctl = NULL;
|
||||
@ -5369,7 +5369,7 @@ static int bind_parse_tls_ticket_keys(char **args, int cur_arg, struct proxy *px
|
||||
return 0;
|
||||
}
|
||||
|
||||
keys_ref = malloc(sizeof(struct tls_keys_ref));
|
||||
keys_ref = malloc(sizeof(*keys_ref));
|
||||
keys_ref->tlskeys = malloc(TLS_TICKETS_NO * sizeof(struct tls_sess_key));
|
||||
|
||||
if ((f = fopen(args[cur_arg + 1], "r")) == NULL) {
|
||||
|
@ -242,7 +242,7 @@ struct uri_auth *stats_add_auth(struct uri_auth **root, char *user)
|
||||
return u;
|
||||
}
|
||||
|
||||
newuser = calloc(1, sizeof(struct auth_users));
|
||||
newuser = calloc(1, sizeof(*newuser));
|
||||
if (!newuser)
|
||||
return NULL;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user