fix xcalloc() argument order

Pass the number of elements first and ther size second, as expected
by xcalloc().  Provide a semantic patch, which was actually used to
generate the rest of this patch.

The semantic patch would generate flip-flop diffs if both arguments
are sizeofs.  We don't have such a case, and it's hard to imagine
the usefulness of such an allocation.  If it ever occurs then we
could deal with it by duplicating the rule in the semantic patch to
make it cancel itself out, or we could change the code to use
CALLOC_ARRAY.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
René Scharfe
2021-03-06 12:26:19 +01:00
committed by Junio C Hamano
parent 59ec22464f
commit 241b5d3ebe
6 changed files with 28 additions and 17 deletions

View File

@ -413,7 +413,7 @@ struct file_item {
static void add_file_item(struct string_list *files, const char *name)
{
struct file_item *item = xcalloc(sizeof(*item), 1);
struct file_item *item = xcalloc(1, sizeof(*item));
string_list_append(files, name)->util = item;
}
@ -476,7 +476,7 @@ static void collect_changes_cb(struct diff_queue_struct *q,
add_file_item(s->files, name);
entry = xcalloc(sizeof(*entry), 1);
entry = xcalloc(1, sizeof(*entry));
hashmap_entry_init(&entry->ent, hash);
entry->name = s->files->items[s->files->nr - 1].string;
entry->item = s->files->items[s->files->nr - 1].util;
@ -1120,7 +1120,7 @@ int run_add_i(struct repository *r, const struct pathspec *ps)
int res = 0;
for (i = 0; i < ARRAY_SIZE(command_list); i++) {
struct command_item *util = xcalloc(sizeof(*util), 1);
struct command_item *util = xcalloc(1, sizeof(*util));
util->command = command_list[i].command;
string_list_append(&commands.items, command_list[i].string)
->util = util;