From 241b5d3ebeea21b70a74fdc8c74e73f7ed829cb1 Mon Sep 17 00:00:00 2001 From: René Scharfe Date: Sat, 6 Mar 2021 12:26:19 +0100 Subject: fix xcalloc() argument order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- ref-filter.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ref-filter.c') diff --git a/ref-filter.c b/ref-filter.c index ee337df232..033cd4f9f2 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -768,7 +768,8 @@ static int if_atom_handler(struct atom_value *atomv, struct ref_formatting_state struct strbuf *unused_err) { struct ref_formatting_stack *new_stack; - struct if_then_else *if_then_else = xcalloc(sizeof(struct if_then_else), 1); + struct if_then_else *if_then_else = xcalloc(1, + sizeof(struct if_then_else)); if_then_else->str = atomv->atom->u.if_then_else.str; if_then_else->cmp_status = atomv->atom->u.if_then_else.cmp_status; @@ -2242,7 +2243,7 @@ static void reach_filter(struct ref_array *array, if (!check_reachable) return; - to_clear = xcalloc(sizeof(struct commit *), array->nr); + to_clear = xcalloc(array->nr, sizeof(struct commit *)); repo_init_revisions(the_repository, &revs, NULL); -- cgit v1.2.3