Skip to content

Commit bfcc6e2

Browse files
committed
Merge branch 'rs/xcalloc-takes-nelem-first'
Code cleanup. * rs/xcalloc-takes-nelem-first: fix xcalloc() argument order
2 parents af10702 + 241b5d3 commit bfcc6e2

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

add-interactive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ struct file_item {
413413

414414
static void add_file_item(struct string_list *files, const char *name)
415415
{
416-
struct file_item *item = xcalloc(sizeof(*item), 1);
416+
struct file_item *item = xcalloc(1, sizeof(*item));
417417

418418
string_list_append(files, name)->util = item;
419419
}
@@ -1120,7 +1120,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
11201120
int res = 0;
11211121

11221122
for (i = 0; i < ARRAY_SIZE(command_list); i++) {
1123-
struct command_item *util = xcalloc(sizeof(*util), 1);
1123+
struct command_item *util = xcalloc(1, sizeof(*util));
11241124
util->command = command_list[i].command;
11251125
string_list_append(&commands.items, command_list[i].string)
11261126
->util = util;

contrib/coccinelle/xcalloc.cocci

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@@
2+
type T;
3+
T *ptr;
4+
expression n;
5+
@@
6+
xcalloc(
7+
+ n,
8+
\( sizeof(T) \| sizeof(*ptr) \)
9+
- , n
10+
)

ref-filter.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ static int if_atom_handler(struct atom_value *atomv, struct ref_formatting_state
772772
struct strbuf *unused_err)
773773
{
774774
struct ref_formatting_stack *new_stack;
775-
struct if_then_else *if_then_else = xcalloc(sizeof(struct if_then_else), 1);
775+
struct if_then_else *if_then_else = xcalloc(1,
776+
sizeof(struct if_then_else));
776777

777778
if_then_else->str = atomv->atom->u.if_then_else.str;
778779
if_then_else->cmp_status = atomv->atom->u.if_then_else.cmp_status;

trailer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static void print_all(FILE *outfile, struct list_head *head,
174174

175175
static struct trailer_item *trailer_from_arg(struct arg_item *arg_tok)
176176
{
177-
struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1);
177+
struct trailer_item *new_item = xcalloc(1, sizeof(*new_item));
178178
new_item->token = arg_tok->token;
179179
new_item->value = arg_tok->value;
180180
arg_tok->token = arg_tok->value = NULL;
@@ -664,7 +664,7 @@ static void parse_trailer(struct strbuf *tok, struct strbuf *val,
664664
static struct trailer_item *add_trailer_item(struct list_head *head, char *tok,
665665
char *val)
666666
{
667-
struct trailer_item *new_item = xcalloc(sizeof(*new_item), 1);
667+
struct trailer_item *new_item = xcalloc(1, sizeof(*new_item));
668668
new_item->token = tok;
669669
new_item->value = val;
670670
list_add_tail(&new_item->list, head);
@@ -675,7 +675,7 @@ static void add_arg_item(struct list_head *arg_head, char *tok, char *val,
675675
const struct conf_info *conf,
676676
const struct new_trailer_item *new_trailer_item)
677677
{
678-
struct arg_item *new_item = xcalloc(sizeof(*new_item), 1);
678+
struct arg_item *new_item = xcalloc(1, sizeof(*new_item));
679679
new_item->token = tok;
680680
new_item->value = val;
681681
duplicate_conf(&new_item->conf, conf);

0 commit comments

Comments
 (0)