{"thread":{"id":"55306","subject":"[PATCH 1/2] git-compat-util.h: drop trailing semicolon from macro definition","startedAt":"2021-03-13T16:12:00Z","lastAt":"2021-03-16T11:43:59Z","messageCount":5,"participants":["René Scharfe.","Junio C Hamano","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"419042","messageId":"b417c7cc-8e40-04df-0314-d4c3fab278b7@web.de","threadId":"55306","inReplyTo":null,"subject":"[PATCH 1/2] git-compat-util.h: drop trailing semicolon from macro definition","fromName":"René Scharfe.","fromEmail":"l.s.r@web.de","sentAt":"2021-03-13T16:10:47Z","receivedAt":"2021-03-13T16:12:00Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Make CALLOC_ARRAY usable like a function by requiring callers to supply\nthe trailing semicolon, which all of the current ones already do.  With\nthe extra semicolon e.g. the following code wouldn't compile because it\ndisconnects the \"else\" from the \"if\":\n\n\tif (condition)\n\t\tCALLOC_ARRAY(ptr, n);\n\telse\n\t\twhatever();\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n git-compat-util.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 3b2738c73d..dcc786edaa 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -898,7 +898,7 @@ int xstrncmpz(const char *s, const char *t, size_t len);\n #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n\n #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n-#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)));\n+#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n\n #define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n--\n2.30.2\n"},{"id":"419045","messageId":"b2942f67-f0c0-872b-9b8c-11b6ea295412@web.de","threadId":"55306","inReplyTo":"b417c7cc-8e40-04df-0314-d4c3fab278b7@web.de","subject":"[PATCH 2/2] use CALLOC_ARRAY","fromName":"René Scharfe.","fromEmail":"l.s.r@web.de","sentAt":"2021-03-13T16:17:22Z","receivedAt":"2021-03-13T16:18:30Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add and apply a semantic patch for converting code that open-codes\nCALLOC_ARRAY to use it instead.  It shortens the code and infers the\nelement size automatically.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n add-interactive.c              |  2 +-\n apply.c                        |  6 +++---\n archive-tar.c                  |  2 +-\n attr.c                         | 12 ++++++------\n bisect.c                       |  2 +-\n blame.c                        | 17 ++++++++---------\n bloom.c                        |  2 +-\n builtin/clean.c                |  2 +-\n builtin/fast-import.c          |  8 ++++----\n builtin/grep.c                 |  2 +-\n builtin/index-pack.c           | 10 +++++-----\n builtin/ls-remote.c            |  2 +-\n builtin/merge.c                |  2 +-\n builtin/notes.c                |  2 +-\n builtin/pack-objects.c         |  8 ++++----\n builtin/pack-redundant.c       |  2 +-\n builtin/receive-pack.c         |  4 ++--\n builtin/unpack-objects.c       |  4 ++--\n bulk-checkin.c                 |  2 +-\n cache-tree.c                   |  2 +-\n combine-diff.c                 | 20 ++++++++++----------\n commit-graph.c                 |  4 ++--\n commit-reach.c                 |  6 +++---\n commit.c                       |  4 ++--\n config.c                       |  2 +-\n contrib/coccinelle/array.cocci |  8 ++++++++\n convert.c                      |  2 +-\n daemon.c                       |  4 ++--\n decorate.c                     |  2 +-\n diff.c                         | 10 ++++------\n diffcore-rename.c              |  3 +--\n dir.c                          |  6 +++---\n ewah/bitmap.c                  |  2 +-\n fetch-pack.c                   |  2 +-\n fmt-merge-msg.c                |  2 +-\n grep.c                         |  8 ++++----\n hashmap.c                      |  2 +-\n http-backend.c                 |  2 +-\n http-push.c                    |  4 ++--\n http.c                         |  4 ++--\n imap-send.c                    |  4 ++--\n line-log.c                     |  2 +-\n line-range.c                   |  2 +-\n list-objects-filter.c          |  6 +++---\n ll-merge.c                     |  2 +-\n mailmap.c                      |  2 +-\n merge-ort.c                    |  9 ++++-----\n merge-recursive.c              |  9 ++++-----\n midx.c                         |  8 ++++----\n name-hash.c                    |  8 ++++----\n negotiator/default.c           |  2 +-\n negotiator/skipping.c          |  4 ++--\n notes-merge.c                  |  2 +-\n notes-utils.c                  |  2 +-\n notes.c                        |  2 +-\n object-file.c                  |  2 +-\n object.c                       |  4 ++--\n pack-bitmap.c                  |  4 ++--\n pack-objects.c                 |  2 +-\n packfile.c                     |  2 +-\n patch-ids.c                    |  2 +-\n pathspec.c                     |  4 ++--\n pretty.c                       |  2 +-\n progress.c                     |  2 +-\n promisor-remote.c              |  2 +-\n range-diff.c                   |  2 +-\n read-cache.c                   |  8 ++++----\n ref-filter.c                   |  6 +++---\n reflog-walk.c                  |  4 ++--\n refs.c                         |  4 ++--\n refs/files-backend.c           | 10 +++++-----\n refs/iterator.c                |  2 +-\n refs/packed-backend.c          |  4 ++--\n refs/ref-cache.c               |  2 +-\n remote.c                       |  8 ++++----\n repository.c                   |  4 ++--\n resolve-undo.c                 |  4 ++--\n revision.c                     |  6 +++---\n run-command.c                  |  4 ++--\n send-pack.c                    |  4 ++--\n sequencer.c                    |  2 +-\n server-info.c                  |  2 +-\n split-index.c                  |  4 ++--\n trailer.c                      |  2 +-\n transport-helper.c             |  4 ++--\n transport.c                    |  2 +-\n worktree.c                     |  4 ++--\n wt-status.c                    |  6 +++---\n 88 files changed, 190 insertions(+), 188 deletions(-)\n\ndiff --git a/add-interactive.c b/add-interactive.c\nindex 09faee0e8f..36ebdbdf7e 100644\n--- a/add-interactive.c\n+++ b/add-interactive.c\n@@ -476,7 +476,7 @@ static void collect_changes_cb(struct diff_queue_struct *q,\n\n \t\t\tadd_file_item(s->files, name);\n\n-\t\t\tentry = xcalloc(1, sizeof(*entry));\n+\t\t\tCALLOC_ARRAY(entry, 1);\n \t\t\thashmap_entry_init(&entry->ent, hash);\n \t\t\tentry->name = s->files->items[s->files->nr - 1].string;\n \t\t\tentry->item = s->files->items[s->files->nr - 1].util;\ndiff --git a/apply.c b/apply.c\nindex 668b16e989..6695a931e9 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -1781,7 +1781,7 @@ static int parse_single_patch(struct apply_state *state,\n \t\tstruct fragment *fragment;\n \t\tint len;\n\n-\t\tfragment = xcalloc(1, sizeof(*fragment));\n+\t\tCALLOC_ARRAY(fragment, 1);\n \t\tfragment->linenr = state->linenr;\n \t\tlen = parse_fragment(state, line, size, patch, fragment);\n \t\tif (len <= 0) {\n@@ -1959,7 +1959,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,\n \t\tsize -= llen;\n \t}\n\n-\tfrag = xcalloc(1, sizeof(*frag));\n+\tCALLOC_ARRAY(frag, 1);\n \tfrag->patch = inflate_it(data, hunk_size, origlen);\n \tfrag->free_patch = 1;\n \tif (!frag->patch)\n@@ -4681,7 +4681,7 @@ static int apply_patch(struct apply_state *state,\n \t\tstruct patch *patch;\n \t\tint nr;\n\n-\t\tpatch = xcalloc(1, sizeof(*patch));\n+\t\tCALLOC_ARRAY(patch, 1);\n \t\tpatch->inaccurate_eof = !!(options & APPLY_OPT_INACCURATE_EOF);\n \t\tpatch->recount =  !!(options & APPLY_OPT_RECOUNT);\n \t\tnr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch);\ndiff --git a/archive-tar.c b/archive-tar.c\nindex a971fdc0f6..05d2455870 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -371,7 +371,7 @@ static int tar_filter_config(const char *var, const char *value, void *data)\n\n \tar = find_tar_filter(name, namelen);\n \tif (!ar) {\n-\t\tar = xcalloc(1, sizeof(*ar));\n+\t\tCALLOC_ARRAY(ar, 1);\n \t\tar->name = xmemdupz(name, namelen);\n \t\tar->write_archive = write_tar_filter_archive;\n \t\tar->flags = ARCHIVER_WANT_COMPRESSION_LEVELS |\ndiff --git a/attr.c b/attr.c\nindex 4ef85d668b..59a8d8af1a 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -569,7 +569,7 @@ struct attr_check *attr_check_initl(const char *one, ...)\n \tcheck = attr_check_alloc();\n \tcheck->nr = cnt;\n \tcheck->alloc = cnt;\n-\tcheck->items = xcalloc(cnt, sizeof(struct attr_check_item));\n+\tCALLOC_ARRAY(check->items, cnt);\n\n \tcheck->items[0].attr = git_attr(one);\n \tva_start(params, one);\n@@ -670,7 +670,7 @@ static struct attr_stack *read_attr_from_array(const char **list)\n \tconst char *line;\n \tint lineno = 0;\n\n-\tres = xcalloc(1, sizeof(*res));\n+\tCALLOC_ARRAY(res, 1);\n \twhile ((line = *(list++)) != NULL)\n \t\thandle_attr_line(res, line, \"[builtin]\", ++lineno, 1);\n \treturn res;\n@@ -707,7 +707,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)\n\n \tif (!fp)\n \t\treturn NULL;\n-\tres = xcalloc(1, sizeof(*res));\n+\tCALLOC_ARRAY(res, 1);\n \twhile (fgets(buf, sizeof(buf), fp)) {\n \t\tchar *bufp = buf;\n \t\tif (!lineno)\n@@ -733,7 +733,7 @@ static struct attr_stack *read_attr_from_index(const struct index_state *istate,\n \tif (!buf)\n \t\treturn NULL;\n\n-\tres = xcalloc(1, sizeof(*res));\n+\tCALLOC_ARRAY(res, 1);\n \tfor (sp = buf; *sp; ) {\n \t\tchar *ep;\n \t\tint more;\n@@ -774,7 +774,7 @@ static struct attr_stack *read_attr(const struct index_state *istate,\n \t}\n\n \tif (!res)\n-\t\tres = xcalloc(1, sizeof(*res));\n+\t\tCALLOC_ARRAY(res, 1);\n \treturn res;\n }\n\n@@ -874,7 +874,7 @@ static void bootstrap_attr_stack(const struct index_state *istate,\n \telse\n \t\te = NULL;\n \tif (!e)\n-\t\te = xcalloc(1, sizeof(struct attr_stack));\n+\t\tCALLOC_ARRAY(e, 1);\n \tpush_stack(stack, e, NULL, 0);\n }\n\ndiff --git a/bisect.c b/bisect.c\nindex ae48d19acf..af2863d044 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -423,7 +423,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches,\n \tshow_list(\"bisection 2 sorted\", 0, nr, list);\n\n \t*all = nr;\n-\tweights = xcalloc(on_list, sizeof(*weights));\n+\tCALLOC_ARRAY(weights, on_list);\n\n \t/* Do the real work of finding bisection commit. */\n \tbest = do_find_bisection(list, nr, weights, bisect_flags);\ndiff --git a/blame.c b/blame.c\nindex d6a3f5b70b..5018bb8fb2 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -951,13 +951,13 @@ static int *fuzzy_find_matching_lines(struct blame_origin *parent,\n \tmax_search_distance_b = ((2 * max_search_distance_a + 1) * length_b\n \t\t\t\t - 1) / length_a;\n\n-\tresult = xcalloc(length_b, sizeof(int));\n-\tsecond_best_result = xcalloc(length_b, sizeof(int));\n-\tcertainties = xcalloc(length_b, sizeof(int));\n+\tCALLOC_ARRAY(result, length_b);\n+\tCALLOC_ARRAY(second_best_result, length_b);\n+\tCALLOC_ARRAY(certainties, length_b);\n\n \t/* See get_similarity() for details of similarities. */\n \tsimilarity_count = length_b * (max_search_distance_a * 2 + 1);\n-\tsimilarities = xcalloc(similarity_count, sizeof(int));\n+\tCALLOC_ARRAY(similarities, similarity_count);\n\n \tfor (i = 0; i < length_b; ++i) {\n \t\tresult[i] = -1;\n@@ -995,7 +995,7 @@ static void fill_origin_fingerprints(struct blame_origin *o)\n \t\treturn;\n \to->num_lines = find_line_starts(&line_starts, o->file.ptr,\n \t\t\t\t\to->file.size);\n-\to->fingerprints = xcalloc(o->num_lines, sizeof(struct fingerprint));\n+\tCALLOC_ARRAY(o->fingerprints, o->num_lines);\n \tget_line_fingerprints(o->fingerprints, o->file.ptr, line_starts,\n \t\t\t      0, o->num_lines);\n \tfree(line_starts);\n@@ -1853,8 +1853,7 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,\n \tdiffp = NULL;\n\n \tif (ignore_diffs && same - tlno > 0) {\n-\t\tline_blames = xcalloc(same - tlno,\n-\t\t\t\t      sizeof(struct blame_line_tracker));\n+\t\tCALLOC_ARRAY(line_blames, same - tlno);\n \t\tguess_line_blames(parent, target, tlno, offset, same,\n \t\t\t\t  parent_len, line_blames);\n \t}\n@@ -2216,7 +2215,7 @@ static struct blame_list *setup_blame_list(struct blame_entry *unblamed,\n \tfor (e = unblamed, num_ents = 0; e; e = e->next)\n \t\tnum_ents++;\n \tif (num_ents) {\n-\t\tblame_list = xcalloc(num_ents, sizeof(struct blame_list));\n+\t\tCALLOC_ARRAY(blame_list, num_ents);\n \t\tfor (e = unblamed, i = 0; e; e = e->next)\n \t\t\tblame_list[i++].ent = e;\n \t}\n@@ -2428,7 +2427,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,\n \telse if (num_sg < ARRAY_SIZE(sg_buf))\n \t\tmemset(sg_buf, 0, sizeof(sg_buf));\n \telse\n-\t\tsg_origin = xcalloc(num_sg, sizeof(*sg_origin));\n+\t\tCALLOC_ARRAY(sg_origin, num_sg);\n\n \t/*\n \t * The first pass looks for unrenamed path to optimize for\ndiff --git a/bloom.c b/bloom.c\nindex b176f28f53..52b87474c6 100644\n--- a/bloom.c\n+++ b/bloom.c\n@@ -277,7 +277,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,\n \t\t\t\t*computed |= BLOOM_TRUNC_EMPTY;\n \t\t\tfilter->len = 1;\n \t\t}\n-\t\tfilter->data = xcalloc(filter->len, sizeof(unsigned char));\n+\t\tCALLOC_ARRAY(filter->data, filter->len);\n\n \t\thashmap_for_each_entry(&pathmap, &iter, e, entry) {\n \t\t\tstruct bloom_key key;\ndiff --git a/builtin/clean.c b/builtin/clean.c\nindex 687ab473c2..995053b791 100644\n--- a/builtin/clean.c\n+++ b/builtin/clean.c\n@@ -623,7 +623,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)\n \t\t\t\tnr += chosen[i];\n \t\t}\n\n-\t\tresult = xcalloc(st_add(nr, 1), sizeof(int));\n+\t\tCALLOC_ARRAY(result, st_add(nr, 1));\n \t\tfor (i = 0; i < stuff->nr && j < nr; i++) {\n \t\t\tif (chosen[i])\n \t\t\t\tresult[j++] = i;\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex dd4d09cece..3afa81cf9a 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -3322,7 +3322,7 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)\n \t\tdie(_(\"Expected format name:filename for submodule rewrite option\"));\n \t*f = '\\0';\n \tf++;\n-\tms = xcalloc(1, sizeof(*ms));\n+\tCALLOC_ARRAY(ms, 1);\n\n \tfp = fopen(f, \"r\");\n \tif (!fp)\n@@ -3519,9 +3519,9 @@ int cmd_fast_import(int argc, const char **argv, const char *prefix)\n\n \talloc_objects(object_entry_alloc);\n \tstrbuf_init(&command_buf, 0);\n-\tatom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));\n-\tbranch_table = xcalloc(branch_table_sz, sizeof(struct branch*));\n-\tavail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));\n+\tCALLOC_ARRAY(atom_table, atom_table_sz);\n+\tCALLOC_ARRAY(branch_table, branch_table_sz);\n+\tCALLOC_ARRAY(avail_tree_table, avail_tree_table_sz);\n \tmarks = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set));\n\n \thashmap_init(&object_table, object_entry_hashcmp, NULL, 0);\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 4e91a253ac..ccd8d08f3d 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -211,7 +211,7 @@ static void start_threads(struct grep_opt *opt)\n \t\tstrbuf_init(&todo[i].out, 0);\n \t}\n\n-\tthreads = xcalloc(num_threads, sizeof(*threads));\n+\tCALLOC_ARRAY(threads, num_threads);\n \tfor (i = 0; i < num_threads; i++) {\n \t\tint err;\n \t\tstruct grep_opt *o = grep_opt_dup(opt);\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex bad5748807..21899687e2 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -185,7 +185,7 @@ static void init_thread(void)\n \tif (show_stat)\n \t\tpthread_mutex_init(&deepest_delta_mutex, NULL);\n \tpthread_key_create(&key, NULL);\n-\tthread_data = xcalloc(nr_threads, sizeof(*thread_data));\n+\tCALLOC_ARRAY(thread_data, nr_threads);\n \tfor (i = 0; i < nr_threads; i++) {\n \t\tthread_data[i].pack_fd = open(curr_pack, O_RDONLY);\n \t\tif (thread_data[i].pack_fd == -1)\n@@ -1674,7 +1674,7 @@ static void show_pack_info(int stat_only)\n \tunsigned long *chain_histogram = NULL;\n\n \tif (deepest_delta)\n-\t\tchain_histogram = xcalloc(deepest_delta, sizeof(unsigned long));\n+\t\tCALLOC_ARRAY(chain_histogram, deepest_delta);\n\n \tfor (i = 0; i < nr_objects; i++) {\n \t\tstruct object_entry *obj = &objects[i];\n@@ -1912,10 +1912,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n\n \tcurr_pack = open_pack_file(pack_name);\n \tparse_pack_header();\n-\tobjects = xcalloc(st_add(nr_objects, 1), sizeof(struct object_entry));\n+\tCALLOC_ARRAY(objects, st_add(nr_objects, 1));\n \tif (show_stat)\n-\t\tobj_stat = xcalloc(st_add(nr_objects, 1), sizeof(struct object_stat));\n-\tofs_deltas = xcalloc(nr_objects, sizeof(struct ofs_delta_entry));\n+\t\tCALLOC_ARRAY(obj_stat, st_add(nr_objects, 1));\n+\tCALLOC_ARRAY(ofs_deltas, nr_objects);\n \tparse_pack_objects(pack_hash);\n \tif (report_end_of_input)\n \t\twrite_in_full(2, \"\\0\", 1);\ndiff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\nindex ef604752a0..abfa984737 100644\n--- a/builtin/ls-remote.c\n+++ b/builtin/ls-remote.c\n@@ -88,7 +88,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)\n\n \tif (argc > 1) {\n \t\tint i;\n-\t\tpattern = xcalloc(argc, sizeof(const char *));\n+\t\tCALLOC_ARRAY(pattern, argc);\n \t\tfor (i = 1; i < argc; i++) {\n \t\t\tpattern[i - 1] = xstrfmt(\"*/%s\", argv[i]);\n \t\t}\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex eb00b273e6..388619536a 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -210,7 +210,7 @@ static struct strategy *get_strategy(const char *name)\n \t\texit(1);\n \t}\n\n-\tret = xcalloc(1, sizeof(struct strategy));\n+\tCALLOC_ARRAY(ret, 1);\n \tret->name = xstrdup(name);\n \tret->attr = NO_TRIVIAL;\n \treturn ret;\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 08b8914d29..74bba39ca8 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -730,7 +730,7 @@ static int merge_commit(struct notes_merge_options *o)\n \telse\n \t\toidclr(&parent_oid);\n\n-\tt = xcalloc(1, sizeof(struct notes_tree));\n+\tCALLOC_ARRAY(t, 1);\n \tinit_notes(t, \"NOTES_MERGE_PARTIAL\", combine_notes_overwrite, 0);\n\n \to->local_ref = local_ref_to_free =\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6d62aaf59a..4bb602688c 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1635,7 +1635,7 @@ static void add_preferred_base(struct object_id *oid)\n \t\t}\n \t}\n\n-\tit = xcalloc(1, sizeof(*it));\n+\tCALLOC_ARRAY(it, 1);\n \tit->next = pbase_tree;\n \tpbase_tree = it;\n\n@@ -2096,7 +2096,7 @@ static void get_object_details(void)\n \t\tprogress_state = start_progress(_(\"Counting objects\"),\n \t\t\t\t\t\tto_pack.nr_objects);\n\n-\tsorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *));\n+\tCALLOC_ARRAY(sorted_by_offset, to_pack.nr_objects);\n \tfor (i = 0; i < to_pack.nr_objects; i++)\n \t\tsorted_by_offset[i] = to_pack.objects + i;\n \tQSORT(sorted_by_offset, to_pack.nr_objects, pack_offset_sort);\n@@ -2428,7 +2428,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,\n \tstruct unpacked *array;\n \tunsigned long mem_usage = 0;\n\n-\tarray = xcalloc(window, sizeof(struct unpacked));\n+\tCALLOC_ARRAY(array, window);\n\n \tfor (;;) {\n \t\tstruct object_entry *entry;\n@@ -2665,7 +2665,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,\n \tif (progress > pack_to_stdout)\n \t\tfprintf_ln(stderr, _(\"Delta compression using up to %d threads\"),\n \t\t\t   delta_search_threads);\n-\tp = xcalloc(delta_search_threads, sizeof(*p));\n+\tCALLOC_ARRAY(p, delta_search_threads);\n\n \t/* Partition the work amongst work threads. */\n \tfor (i = 0; i < delta_search_threads; i++) {\ndiff --git a/builtin/pack-redundant.c b/builtin/pack-redundant.c\nindex 6e115a811a..7102996c75 100644\n--- a/builtin/pack-redundant.c\n+++ b/builtin/pack-redundant.c\n@@ -373,7 +373,7 @@ static void sort_pack_list(struct pack_list **pl)\n \t\treturn;\n\n \t/* prepare an array of packed_list for easier sorting */\n-\tary = xcalloc(n, sizeof(struct pack_list *));\n+\tCALLOC_ARRAY(ary, n);\n \tfor (n = 0, p = *pl; p; p = p->next)\n \t\tary[n++] = p;\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex d26040c477..51c8c40fab 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -358,7 +358,7 @@ static void proc_receive_ref_append(const char *prefix)\n \tchar *p;\n \tint len;\n\n-\tref_pattern = xcalloc(1, sizeof(struct proc_receive_ref));\n+\tCALLOC_ARRAY(ref_pattern, 1);\n \tp = strchr(prefix, ':');\n \tif (p) {\n \t\twhile (prefix < p) {\n@@ -1024,7 +1024,7 @@ static int read_proc_receive_report(struct packet_reader *reader,\n \t\t\t}\n \t\t\tif (new_report) {\n \t\t\t\tif (!hint->report) {\n-\t\t\t\t\thint->report = xcalloc(1, sizeof(struct ref_push_report));\n+\t\t\t\t\tCALLOC_ARRAY(hint->report, 1);\n \t\t\t\t\treport = hint->report;\n \t\t\t\t} else {\n \t\t\t\t\treport = hint->report;\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex dd4a75e030..a4ba2ebac6 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -46,7 +46,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base)\n static void add_object_buffer(struct object *object, char *buffer, unsigned long size)\n {\n \tstruct obj_buffer *obj;\n-\tobj = xcalloc(1, sizeof(struct obj_buffer));\n+\tCALLOC_ARRAY(obj, 1);\n \tobj->buffer = buffer;\n \tobj->size = size;\n \tif (add_decoration(&obj_decorate, object, obj))\n@@ -500,7 +500,7 @@ static void unpack_all(void)\n\n \tif (!quiet)\n \t\tprogress = start_progress(_(\"Unpacking objects\"), nr_objects);\n-\tobj_list = xcalloc(nr_objects, sizeof(*obj_list));\n+\tCALLOC_ARRAY(obj_list, nr_objects);\n \tfor (i = 0; i < nr_objects; i++) {\n \t\tunpack_one(i);\n \t\tdisplay_progress(progress, i + 1);\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 583aacb9e3..6f3c97cd34 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -211,7 +211,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n\n \t/* Note: idx is non-NULL when we are writing */\n \tif ((flags & HASH_WRITE_OBJECT) != 0)\n-\t\tidx = xcalloc(1, sizeof(*idx));\n+\t\tCALLOC_ARRAY(idx, 1);\n\n \talready_hashed_to = 0;\n\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 2fb483d3c0..add1f07713 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -564,7 +564,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)\n \t * hence +2.\n \t */\n \tit->subtree_alloc = subtree_nr + 2;\n-\tit->down = xcalloc(it->subtree_alloc, sizeof(struct cache_tree_sub *));\n+\tCALLOC_ARRAY(it->down, it->subtree_alloc);\n \tfor (i = 0; i < subtree_nr; i++) {\n \t\t/* read each subtree */\n \t\tstruct cache_tree *sub;\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 9228aebc16..06635f91bc 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -214,11 +214,11 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,\n \t *   - Else if we have NEW, insert newend lline into base and\n \t *   consume newend\n \t */\n-\tlcs = xcalloc(st_add(origbaselen, 1), sizeof(int*));\n-\tdirections = xcalloc(st_add(origbaselen, 1), sizeof(enum coalesce_direction*));\n+\tCALLOC_ARRAY(lcs, st_add(origbaselen, 1));\n+\tCALLOC_ARRAY(directions, st_add(origbaselen, 1));\n \tfor (i = 0; i < origbaselen + 1; i++) {\n-\t\tlcs[i] = xcalloc(st_add(lennew, 1), sizeof(int));\n-\t\tdirections[i] = xcalloc(st_add(lennew, 1), sizeof(enum coalesce_direction));\n+\t\tCALLOC_ARRAY(lcs[i], st_add(lennew, 1));\n+\t\tCALLOC_ARRAY(directions[i], st_add(lennew, 1));\n \t\tdirections[i][0] = BASE;\n \t}\n \tfor (j = 1; j < lennew + 1; j++)\n@@ -398,8 +398,8 @@ static void consume_hunk(void *state_,\n \t\tstate->lost_bucket = &state->sline[state->nb-1];\n \t}\n \tif (!state->sline[state->nb-1].p_lno)\n-\t\tstate->sline[state->nb-1].p_lno =\n-\t\t\txcalloc(state->num_parent, sizeof(unsigned long));\n+\t\tCALLOC_ARRAY(state->sline[state->nb - 1].p_lno,\n+\t\t\t     state->num_parent);\n \tstate->sline[state->nb-1].p_lno[state->n] = state->ob;\n }\n\n@@ -1159,7 +1159,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \tif (result_size && result[result_size-1] != '\\n')\n \t\tcnt++; /* incomplete line */\n\n-\tsline = xcalloc(st_add(cnt, 2), sizeof(*sline));\n+\tCALLOC_ARRAY(sline, st_add(cnt, 2));\n \tsline[0].bol = result;\n \tfor (lno = 0, cp = result; cp < result + result_size; cp++) {\n \t\tif (*cp == '\\n') {\n@@ -1178,7 +1178,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t/* Even p_lno[cnt+1] is valid -- that is for the end line number\n \t * for deletion hunk at the end.\n \t */\n-\tsline[0].p_lno = xcalloc(st_mult(st_add(cnt, 2), num_parent), sizeof(unsigned long));\n+\tCALLOC_ARRAY(sline[0].p_lno, st_mult(st_add(cnt, 2), num_parent));\n \tfor (lno = 0; lno <= cnt; lno++)\n \t\tsline[lno+1].p_lno = sline[lno].p_lno + num_parent;\n\n@@ -1319,7 +1319,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,\n \tstruct diff_filespec *pool;\n\n \tpair = xmalloc(sizeof(*pair));\n-\tpool = xcalloc(st_add(num_parent, 1), sizeof(struct diff_filespec));\n+\tCALLOC_ARRAY(pool, st_add(num_parent, 1));\n \tpair->one = pool + 1;\n \tpair->two = pool;\n\n@@ -1348,7 +1348,7 @@ static void handle_combined_callback(struct diff_options *opt,\n \tstruct diff_queue_struct q;\n \tint i;\n\n-\tq.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));\n+\tCALLOC_ARRAY(q.queue, num_paths);\n \tq.alloc = num_paths;\n \tq.nr = num_paths;\n \tfor (i = 0, p = paths; p; p = p->next)\ndiff --git a/commit-graph.c b/commit-graph.c\nindex ca025ce8eb..e21eeea42b 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -516,7 +516,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,\n \t\treturn NULL;\n\n \tcount = st.st_size / (the_hash_algo->hexsz + 1);\n-\toids = xcalloc(count, sizeof(struct object_id));\n+\tCALLOC_ARRAY(oids, count);\n\n \tprepare_alt_odb(r);\n\n@@ -2238,7 +2238,7 @@ int write_commit_graph(struct object_directory *odb,\n \tif (!commit_graph_compatible(the_repository))\n \t\treturn 0;\n\n-\tctx = xcalloc(1, sizeof(struct write_commit_graph_context));\n+\tCALLOC_ARRAY(ctx, 1);\n \tctx->r = the_repository;\n \tctx->odb = odb;\n \tctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;\ndiff --git a/commit-reach.c b/commit-reach.c\nindex 2ea84d3dc0..c226ee3da4 100644\n--- a/commit-reach.c\n+++ b/commit-reach.c\n@@ -183,7 +183,7 @@ static int remove_redundant_no_gen(struct repository *r,\n \tint *filled_index;\n \tint i, j, filled;\n\n-\twork = xcalloc(cnt, sizeof(*work));\n+\tCALLOC_ARRAY(work, cnt);\n \tredundant = xcalloc(cnt, 1);\n \tALLOC_ARRAY(filled_index, cnt - 1);\n\n@@ -399,7 +399,7 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,\n\n \t/* There are more than one */\n \tcnt = commit_list_count(result);\n-\trslt = xcalloc(cnt, sizeof(*rslt));\n+\tCALLOC_ARRAY(rslt, cnt);\n \tfor (list = result, i = 0; list; list = list->next)\n \t\trslt[i++] = list->item;\n \tfree_commit_list(result);\n@@ -541,7 +541,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)\n \t\tp->item->object.flags |= STALE;\n \t\tnum_head++;\n \t}\n-\tarray = xcalloc(num_head, sizeof(*array));\n+\tCALLOC_ARRAY(array, num_head);\n \tfor (p = heads, i = 0; p; p = p->next) {\n \t\tif (p->item->object.flags & STALE) {\n \t\t\tarray[i++] = p->item;\ndiff --git a/commit.c b/commit.c\nindex 6ccd774841..42f8117b51 100644\n--- a/commit.c\n+++ b/commit.c\n@@ -1171,7 +1171,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header\n \t * if (verify_signed_buffer(buf, len, buf + len, size - len, ...))\n \t *\twarn(\"warning: signed tag unverified.\");\n \t */\n-\tmergetag = xcalloc(1, sizeof(*mergetag));\n+\tCALLOC_ARRAY(mergetag, 1);\n \tmergetag->key = xstrdup(\"mergetag\");\n \tmergetag->value = buf;\n \tmergetag->len = size;\n@@ -1336,7 +1336,7 @@ static struct commit_extra_header *read_commit_extra_header_lines(\n \t\t\t excluded_header_field(line, eof - line, exclude))\n \t\t\tcontinue;\n\n-\t\tit = xcalloc(1, sizeof(*it));\n+\t\tCALLOC_ARRAY(it, 1);\n \t\tit->key = xmemdupz(line, eof-line);\n \t\t*tail = it;\n \t\ttail = &it->next;\ndiff --git a/config.c b/config.c\nindex f90b633dba..6428393a41 100644\n--- a/config.c\n+++ b/config.c\n@@ -2269,7 +2269,7 @@ static void repo_read_config(struct repository *repo)\n \topts.git_dir = repo->gitdir;\n\n \tif (!repo->config)\n-\t\trepo->config = xcalloc(1, sizeof(struct config_set));\n+\t\tCALLOC_ARRAY(repo->config, 1);\n \telse\n \t\tgit_configset_clear(repo->config);\n\ndiff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci\nindex 46b8d2ee11..9a17d2a121 100644\n--- a/contrib/coccinelle/array.cocci\n+++ b/contrib/coccinelle/array.cocci\n@@ -88,3 +88,11 @@ expression n;\n @@\n - ptr = xmalloc((n) * sizeof(T));\n + ALLOC_ARRAY(ptr, n);\n+\n+@@\n+type T;\n+T *ptr;\n+expression n;\n+@@\n+- ptr = xcalloc(n, \\( sizeof(*ptr) \\| sizeof(T) \\) )\n++ CALLOC_ARRAY(ptr, n)\ndiff --git a/convert.c b/convert.c\nindex ee360c2f07..9ecc1c699c 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -1028,7 +1028,7 @@ static int read_convert_config(const char *var, const char *value, void *cb)\n \t\tif (!strncmp(drv->name, name, namelen) && !drv->name[namelen])\n \t\t\tbreak;\n \tif (!drv) {\n-\t\tdrv = xcalloc(1, sizeof(struct convert_driver));\n+\t\tCALLOC_ARRAY(drv, 1);\n \t\tdrv->name = xmemdupz(name, namelen);\n \t\t*user_convert_tail = drv;\n \t\tuser_convert_tail = &(drv->next);\ndiff --git a/daemon.c b/daemon.c\nindex 2ab7ea82eb..343531980d 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -840,7 +840,7 @@ static void add_child(struct child_process *cld, struct sockaddr *addr, socklen_\n {\n \tstruct child *newborn, **cradle;\n\n-\tnewborn = xcalloc(1, sizeof(*newborn));\n+\tCALLOC_ARRAY(newborn, 1);\n \tlive_children++;\n \tmemcpy(&newborn->cld, cld, sizeof(*cld));\n \tmemcpy(&newborn->address, addr, addrlen);\n@@ -1148,7 +1148,7 @@ static int service_loop(struct socketlist *socklist)\n \tstruct pollfd *pfd;\n \tint i;\n\n-\tpfd = xcalloc(socklist->nr, sizeof(struct pollfd));\n+\tCALLOC_ARRAY(pfd, socklist->nr);\n\n \tfor (i = 0; i < socklist->nr; i++) {\n \t\tpfd[i].fd = socklist->list[i];\ndiff --git a/decorate.c b/decorate.c\nindex a605b1b5f4..2036d15967 100644\n--- a/decorate.c\n+++ b/decorate.c\n@@ -39,7 +39,7 @@ static void grow_decoration(struct decoration *n)\n \tstruct decoration_entry *old_entries = n->entries;\n\n \tn->size = (old_size + 1000) * 3 / 2;\n-\tn->entries = xcalloc(n->size, sizeof(struct decoration_entry));\n+\tCALLOC_ARRAY(n->entries, n->size);\n \tn->nr = 0;\n\n \tfor (i = 0; i < old_size; i++) {\ndiff --git a/diff.c b/diff.c\nindex 6956f5e335..4acccd9d7e 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2233,14 +2233,12 @@ static void init_diff_words_data(struct emit_callback *ecbdata,\n \tstruct diff_options *o = xmalloc(sizeof(struct diff_options));\n \tmemcpy(o, orig_opts, sizeof(struct diff_options));\n\n-\tecbdata->diff_words =\n-\t\txcalloc(1, sizeof(struct diff_words_data));\n+\tCALLOC_ARRAY(ecbdata->diff_words, 1);\n \tecbdata->diff_words->type = o->word_diff;\n \tecbdata->diff_words->opt = o;\n\n \tif (orig_opts->emitted_symbols)\n-\t\to->emitted_symbols =\n-\t\t\txcalloc(1, sizeof(struct emitted_diff_symbols));\n+\t\tCALLOC_ARRAY(o->emitted_symbols, 1);\n\n \tif (!o->word_regex)\n \t\to->word_regex = userdiff_word_regex(one, o->repo->index);\n@@ -2509,7 +2507,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,\n \t\t\t\t\t  const char *name_b)\n {\n \tstruct diffstat_file *x;\n-\tx = xcalloc(1, sizeof(*x));\n+\tCALLOC_ARRAY(x, 1);\n \tALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);\n \tdiffstat->files[diffstat->nr++] = x;\n \tif (name_b) {\n@@ -4918,7 +4916,7 @@ static int diff_opt_find_object(const struct option *option,\n \t\treturn error(_(\"unable to resolve '%s'\"), arg);\n\n \tif (!opt->objfind)\n-\t\topt->objfind = xcalloc(1, sizeof(*opt->objfind));\n+\t\tCALLOC_ARRAY(opt->objfind, 1);\n\n \topt->pickaxe_opts |= DIFF_PICKAXE_KIND_OBJFIND;\n \topt->flags.recursive = 1;\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 41558185ae..9c1478c078 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -787,8 +787,7 @@ void diffcore_rename(struct diff_options *options)\n \t\t\t\t(uint64_t)num_destinations * (uint64_t)num_sources);\n \t}\n\n-\tmx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_destinations),\n-\t\t     sizeof(*mx));\n+\tCALLOC_ARRAY(mx, st_mult(NUM_CANDIDATE_PER_DST, num_destinations));\n \tfor (dst_cnt = i = 0; i < rename_dst_nr; i++) {\n \t\tstruct diff_filespec *two = rename_dst[i].p->two;\n \t\tstruct diff_score *m;\ndiff --git a/dir.c b/dir.c\nindex fd8aa7c40f..19c2fa239b 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -1488,7 +1488,7 @@ static void prep_exclude(struct dir_struct *dir,\n \t\tconst char *cp;\n \t\tstruct oid_stat oid_stat;\n\n-\t\tstk = xcalloc(1, sizeof(*stk));\n+\t\tCALLOC_ARRAY(stk, 1);\n \t\tif (current < 0) {\n \t\t\tcp = base;\n \t\t\tcurrent = 0;\n@@ -3162,7 +3162,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra\n \tint varint_len;\n \tconst unsigned hashsz = the_hash_algo->rawsz;\n\n-\touc = xcalloc(1, sizeof(*ouc));\n+\tCALLOC_ARRAY(ouc, 1);\n \tstat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);\n \tstat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);\n \touc->dir_flags = htonl(untracked->dir_flags);\n@@ -3373,7 +3373,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long\n \tif (next + exclude_per_dir_offset + 1 > end)\n \t\treturn NULL;\n\n-\tuc = xcalloc(1, sizeof(*uc));\n+\tCALLOC_ARRAY(uc, 1);\n \tstrbuf_init(&uc->ident, ident_len);\n \tstrbuf_add(&uc->ident, ident, ident_len);\n \tload_oid_stat(&uc->ss_info_exclude,\ndiff --git a/ewah/bitmap.c b/ewah/bitmap.c\nindex 0d31cdc866..38a47c44db 100644\n--- a/ewah/bitmap.c\n+++ b/ewah/bitmap.c\n@@ -25,7 +25,7 @@\n struct bitmap *bitmap_word_alloc(size_t word_alloc)\n {\n \tstruct bitmap *bitmap = xmalloc(sizeof(struct bitmap));\n-\tbitmap->words = xcalloc(word_alloc, sizeof(eword_t));\n+\tCALLOC_ARRAY(bitmap->words, word_alloc);\n \tbitmap->word_alloc = word_alloc;\n \treturn bitmap;\n }\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 6a61a46428..fb04a76ca2 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1916,7 +1916,7 @@ static void update_shallow(struct fetch_pack_args *args,\n \t * remote is also shallow, check what ref is safe to update\n \t * without updating .git/shallow\n \t */\n-\tstatus = xcalloc(nr_sought, sizeof(*status));\n+\tCALLOC_ARRAY(status, nr_sought);\n \tassign_shallow_commits_to_refs(si, NULL, status);\n \tif (si->nr_ours || si->nr_theirs) {\n \t\tfor (i = 0; i < nr_sought; i++)\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 1e51492a05..0f66818e0f 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -130,7 +130,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)\n \tif (!find_merge_parent(merge_parents, &oid, NULL))\n \t\treturn 0; /* subsumed by other parents */\n\n-\torigin_data = xcalloc(1, sizeof(struct origin_data));\n+\tCALLOC_ARRAY(origin_data, 1);\n \toidcpy(&origin_data->oid, &oid);\n\n \tif (line[len - 1] == '\\n')\ndiff --git a/grep.c b/grep.c\nindex aabfaaa4c3..223035318b 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -621,7 +621,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)\n \tcase GREP_PATTERN: /* atom */\n \tcase GREP_PATTERN_HEAD:\n \tcase GREP_PATTERN_BODY:\n-\t\tx = xcalloc(1, sizeof (struct grep_expr));\n+\t\tCALLOC_ARRAY(x, 1);\n \t\tx->node = GREP_NODE_ATOM;\n \t\tx->u.atom = p;\n \t\t*list = p->next;\n@@ -651,7 +651,7 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)\n \t\tif (!p->next)\n \t\t\tdie(\"--not not followed by pattern expression\");\n \t\t*list = p->next;\n-\t\tx = xcalloc(1, sizeof (struct grep_expr));\n+\t\tCALLOC_ARRAY(x, 1);\n \t\tx->node = GREP_NODE_NOT;\n \t\tx->u.unary = compile_pattern_not(list);\n \t\tif (!x->u.unary)\n@@ -676,7 +676,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)\n \t\ty = compile_pattern_and(list);\n \t\tif (!y)\n \t\t\tdie(\"--and not followed by pattern expression\");\n-\t\tz = xcalloc(1, sizeof (struct grep_expr));\n+\t\tCALLOC_ARRAY(z, 1);\n \t\tz->node = GREP_NODE_AND;\n \t\tz->u.binary.left = x;\n \t\tz->u.binary.right = y;\n@@ -696,7 +696,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)\n \t\ty = compile_pattern_or(list);\n \t\tif (!y)\n \t\t\tdie(\"not a pattern expression %s\", p->pattern);\n-\t\tz = xcalloc(1, sizeof (struct grep_expr));\n+\t\tCALLOC_ARRAY(z, 1);\n \t\tz->node = GREP_NODE_OR;\n \t\tz->u.binary.left = x;\n \t\tz->u.binary.right = y;\ndiff --git a/hashmap.c b/hashmap.c\nindex 5009471800..134d2eec80 100644\n--- a/hashmap.c\n+++ b/hashmap.c\n@@ -76,7 +76,7 @@ unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)\n static void alloc_table(struct hashmap *map, unsigned int size)\n {\n \tmap->tablesize = size;\n-\tmap->table = xcalloc(size, sizeof(struct hashmap_entry *));\n+\tCALLOC_ARRAY(map->table, size);\n\n \t/* calculate resize thresholds for new size */\n \tmap->grow_at = (unsigned int) ((uint64_t) size * HASHMAP_LOAD_FACTOR / 100);\ndiff --git a/http-backend.c b/http-backend.c\nindex a03b4bae22..b329bf63f0 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -39,7 +39,7 @@ static struct string_list *get_parameters(void)\n \tif (!query_params) {\n \t\tconst char *query = getenv(\"QUERY_STRING\");\n\n-\t\tquery_params = xcalloc(1, sizeof(*query_params));\n+\t\tCALLOC_ARRAY(query_params, 1);\n \t\twhile (query && *query) {\n \t\t\tchar *name = url_decode_parameter_name(&query);\n \t\t\tchar *value = url_decode_parameter_value(&query);\ndiff --git a/http-push.c b/http-push.c\nindex 6a4a43e07f..b60d5fcc85 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -896,7 +896,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)\n \tcurl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);\n \tcurl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);\n\n-\tlock = xcalloc(1, sizeof(*lock));\n+\tCALLOC_ARRAY(lock, 1);\n \tlock->timeout = -1;\n\n \tif (start_active_slot(slot)) {\n@@ -1713,7 +1713,7 @@ int cmd_main(int argc, const char **argv)\n \tint new_refs;\n \tstruct ref *ref, *local_refs;\n\n-\trepo = xcalloc(1, sizeof(*repo));\n+\tCALLOC_ARRAY(repo, 1);\n\n \targv++;\n \tfor (i = 1; i < argc; i++, argv++) {\ndiff --git a/http.c b/http.c\nindex f8ea28bb2e..0e31fc21bc 100644\n--- a/http.c\n+++ b/http.c\n@@ -2324,7 +2324,7 @@ struct http_pack_request *new_direct_http_pack_request(\n \toff_t prev_posn = 0;\n \tstruct http_pack_request *preq;\n\n-\tpreq = xcalloc(1, sizeof(*preq));\n+\tCALLOC_ARRAY(preq, 1);\n \tstrbuf_init(&preq->tmpfile, 0);\n\n \tpreq->url = url;\n@@ -2419,7 +2419,7 @@ struct http_object_request *new_http_object_request(const char *base_url,\n \toff_t prev_posn = 0;\n \tstruct http_object_request *freq;\n\n-\tfreq = xcalloc(1, sizeof(*freq));\n+\tCALLOC_ARRAY(freq, 1);\n \tstrbuf_init(&freq->tmpfile, 0);\n \toidcpy(&freq->oid, oid);\n \tfreq->localfile = -1;\ndiff --git a/imap-send.c b/imap-send.c\nindex d0b94f911e..bb085d66d1 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -963,9 +963,9 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c\n \tchar *arg, *rsp;\n \tint s = -1, preauth;\n\n-\tctx = xcalloc(1, sizeof(*ctx));\n+\tCALLOC_ARRAY(ctx, 1);\n\n-\tctx->imap = imap = xcalloc(1, sizeof(*imap));\n+\tctx->imap = CALLOC_ARRAY(imap, 1);\n \timap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n \timap->in_progress_append = &imap->in_progress;\n\ndiff --git a/line-log.c b/line-log.c\nindex 75c8b1acff..51d93310a4 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -296,7 +296,7 @@ static void line_log_data_insert(struct line_log_data **list,\n \t\treturn;\n \t}\n\n-\tp = xcalloc(1, sizeof(struct line_log_data));\n+\tCALLOC_ARRAY(p, 1);\n \tp->path = path;\n \trange_set_append(&p->ranges, begin, end);\n \tif (ip) {\ndiff --git a/line-range.c b/line-range.c\nindex 9b50583dc0..955a8a9535 100644\n--- a/line-range.c\n+++ b/line-range.c\n@@ -202,7 +202,7 @@ static const char *parse_range_funcname(\n \tdrv = userdiff_find_by_path(istate, path);\n \tif (drv && drv->funcname.pattern) {\n \t\tconst struct userdiff_funcname *pe = &drv->funcname;\n-\t\txecfg = xcalloc(1, sizeof(*xecfg));\n+\t\tCALLOC_ARRAY(xecfg, 1);\n \t\txdiff_set_find_func(xecfg, pe->pattern, pe->cflags);\n \t}\n\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex 4ec0041cfb..39e2f15333 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -186,7 +186,7 @@ static enum list_objects_filter_result filter_trees_depth(\n \t\tseen_info = oidmap_get(\n \t\t\t&filter_data->seen_at_depth, &obj->oid);\n \t\tif (!seen_info) {\n-\t\t\tseen_info = xcalloc(1, sizeof(*seen_info));\n+\t\t\tCALLOC_ARRAY(seen_info, 1);\n \t\t\toidcpy(&seen_info->base.oid, &obj->oid);\n \t\t\tseen_info->depth = filter_data->current_depth;\n \t\t\toidmap_put(&filter_data->seen_at_depth, seen_info);\n@@ -626,7 +626,7 @@ static void filter_combine__init(\n \tsize_t sub;\n\n \td->nr = filter_options->sub_nr;\n-\td->sub = xcalloc(d->nr, sizeof(*d->sub));\n+\tCALLOC_ARRAY(d->sub, d->nr);\n \tfor (sub = 0; sub < d->nr; sub++)\n \t\td->sub[sub].filter = list_objects_filter__init(\n \t\t\tfilter->omits ? &d->sub[sub].omits : NULL,\n@@ -674,7 +674,7 @@ struct filter *list_objects_filter__init(\n \tif (!init_fn)\n \t\treturn NULL;\n\n-\tfilter = xcalloc(1, sizeof(*filter));\n+\tCALLOC_ARRAY(filter, 1);\n \tfilter->omits = omitted;\n \tinit_fn(filter_options, filter);\n \treturn filter;\ndiff --git a/ll-merge.c b/ll-merge.c\nindex 1ec0b959e0..9a8a2c365c 100644\n--- a/ll-merge.c\n+++ b/ll-merge.c\n@@ -268,7 +268,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)\n \t\tif (!strncmp(fn->name, name, namelen) && !fn->name[namelen])\n \t\t\tbreak;\n \tif (!fn) {\n-\t\tfn = xcalloc(1, sizeof(struct ll_merge_driver));\n+\t\tCALLOC_ARRAY(fn, 1);\n \t\tfn->name = xmemdupz(name, namelen);\n \t\tfn->fn = ll_ext_merge;\n \t\t*ll_user_merge_tail = fn;\ndiff --git a/mailmap.c b/mailmap.c\nindex 9bb9cf8b30..183a2f65ee 100644\n--- a/mailmap.c\n+++ b/mailmap.c\n@@ -83,7 +83,7 @@ static void add_mapping(struct string_list *map,\n \tif (item->util) {\n \t\tme = (struct mailmap_entry *)item->util;\n \t} else {\n-\t\tme = xcalloc(1, sizeof(struct mailmap_entry));\n+\t\tCALLOC_ARRAY(me, 1);\n \t\tme->namemap.strdup_strings = 1;\n \t\tme->namemap.cmp = namemap_cmp;\n \t\titem->util = me;\ndiff --git a/merge-ort.c b/merge-ort.c\nindex 603d30c521..92dea35e57 100644\n--- a/merge-ort.c\n+++ b/merge-ort.c\n@@ -1576,8 +1576,7 @@ static void compute_collisions(struct strmap *collisions,\n \t\tif (collision_info) {\n \t\t\tfree(new_path);\n \t\t} else {\n-\t\t\tcollision_info = xcalloc(1,\n-\t\t\t\t\t\t sizeof(struct collision_info));\n+\t\t\tCALLOC_ARRAY(collision_info, 1);\n \t\t\tstring_list_init(&collision_info->source_files, 0);\n \t\t\tstrmap_put(collisions, new_path, collision_info);\n \t\t}\n@@ -1718,7 +1717,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,\n \t\tstruct conflict_info *dir_ci;\n \t\tchar *cur_dir = dirs_to_insert.items[i].string;\n\n-\t\tdir_ci = xcalloc(1, sizeof(*dir_ci));\n+\t\tCALLOC_ARRAY(dir_ci, 1);\n\n \t\tdir_ci->merged.directory_name = parent_name;\n \t\tlen = strlen(parent_name);\n@@ -2703,7 +2702,7 @@ static void process_entry(struct merge_options *opt,\n \t\t * the directory to remain here, so we need to move this\n \t\t * path to some new location.\n \t\t */\n-\t\tnew_ci = xcalloc(1, sizeof(*new_ci));\n+\t\tCALLOC_ARRAY(new_ci, 1);\n \t\t/* We don't really want new_ci->merged.result copied, but it'll\n \t\t * be overwritten below so it doesn't matter.  We also don't\n \t\t * want any directory mode/oid values copied, but we'll zero\n@@ -3083,7 +3082,7 @@ static int checkout(struct merge_options *opt,\n \tunpack_opts.verbose_update = (opt->verbosity > 2);\n \tunpack_opts.fn = twoway_merge;\n \tif (1/* FIXME: opts->overwrite_ignore*/) {\n-\t\tunpack_opts.dir = xcalloc(1, sizeof(*unpack_opts.dir));\n+\t\tCALLOC_ARRAY(unpack_opts.dir, 1);\n \t\tunpack_opts.dir->flags |= DIR_SHOW_IGNORED;\n \t\tsetup_standard_excludes(unpack_opts.dir);\n \t}\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex b052974f19..b69e694d98 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -303,7 +303,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,\n \t\treturn;\n \t}\n\n-\tci = xcalloc(1, sizeof(struct rename_conflict_info));\n+\tCALLOC_ARRAY(ci, 1);\n \tci->rename_type = rename_type;\n \tci->ren1 = ren1;\n \tci->ren2 = ren2;\n@@ -2389,8 +2389,7 @@ static void compute_collisions(struct hashmap *collisions,\n \t\t\tcontinue;\n \t\tcollision_ent = collision_find_entry(collisions, new_path);\n \t\tif (!collision_ent) {\n-\t\t\tcollision_ent = xcalloc(1,\n-\t\t\t\t\t\tsizeof(struct collision_entry));\n+\t\t\tCALLOC_ARRAY(collision_ent, 1);\n \t\t\thashmap_entry_init(&collision_ent->ent,\n \t\t\t\t\t\tstrhash(new_path));\n \t\t\thashmap_put(collisions, &collision_ent->ent);\n@@ -2594,7 +2593,7 @@ static struct string_list *get_renames(struct merge_options *opt,\n \tstruct string_list *renames;\n\n \tcompute_collisions(&collisions, dir_renames, pairs);\n-\trenames = xcalloc(1, sizeof(struct string_list));\n+\tCALLOC_ARRAY(renames, 1);\n\n \tfor (i = 0; i < pairs->nr; ++i) {\n \t\tstruct string_list_item *item;\n@@ -3664,7 +3663,7 @@ static int merge_start(struct merge_options *opt, struct tree *head)\n \t\treturn -1;\n \t}\n\n-\topt->priv = xcalloc(1, sizeof(*opt->priv));\n+\tCALLOC_ARRAY(opt->priv, 1);\n \tstring_list_init(&opt->priv->df_conflict_file_set, 1);\n \treturn 0;\n }\ndiff --git a/midx.c b/midx.c\nindex 971faa8cfc..becfafe65e 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -145,8 +145,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local\n\n \tm->num_objects = ntohl(m->chunk_oid_fanout[255]);\n\n-\tm->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));\n-\tm->packs = xcalloc(m->num_packs, sizeof(*m->packs));\n+\tCALLOC_ARRAY(m->pack_names, m->num_packs);\n+\tCALLOC_ARRAY(m->packs, m->num_packs);\n\n \tcur_pack_name = (const char *)m->chunk_pack_names;\n \tfor (i = 0; i < m->num_packs; i++) {\n@@ -1144,7 +1144,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla\n \tif (!m)\n \t\treturn 0;\n\n-\tcount = xcalloc(m->num_packs, sizeof(uint32_t));\n+\tCALLOC_ARRAY(count, m->num_packs);\n\n \tif (flags & MIDX_PROGRESS)\n \t\tprogress = start_delayed_progress(_(\"Counting referenced objects\"),\n@@ -1315,7 +1315,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,\n \tif (!m)\n \t\treturn 0;\n\n-\tinclude_pack = xcalloc(m->num_packs, sizeof(unsigned char));\n+\tCALLOC_ARRAY(include_pack, m->num_packs);\n\n \tif (batch_size) {\n \t\tif (fill_included_packs_batch(r, m, include_pack, batch_size))\ndiff --git a/name-hash.c b/name-hash.c\nindex 4e03fac9bb..ce28f3f070 100644\n--- a/name-hash.c\n+++ b/name-hash.c\n@@ -225,7 +225,7 @@ static void init_dir_mutex(void)\n {\n \tint j;\n\n-\tlazy_dir_mutex_array = xcalloc(LAZY_MAX_MUTEX, sizeof(pthread_mutex_t));\n+\tCALLOC_ARRAY(lazy_dir_mutex_array, LAZY_MAX_MUTEX);\n\n \tfor (j = 0; j < LAZY_MAX_MUTEX; j++)\n \t\tinit_recursive_mutex(&lazy_dir_mutex_array[j]);\n@@ -514,9 +514,9 @@ static void threaded_lazy_init_name_hash(\n \tk_start = 0;\n \tnr_each = DIV_ROUND_UP(istate->cache_nr, lazy_nr_dir_threads);\n\n-\tlazy_entries = xcalloc(istate->cache_nr, sizeof(struct lazy_entry));\n-\ttd_dir = xcalloc(lazy_nr_dir_threads, sizeof(struct lazy_dir_thread_data));\n-\ttd_name = xcalloc(1, sizeof(struct lazy_name_thread_data));\n+\tCALLOC_ARRAY(lazy_entries, istate->cache_nr);\n+\tCALLOC_ARRAY(td_dir, lazy_nr_dir_threads);\n+\tCALLOC_ARRAY(td_name, 1);\n\n \tinit_dir_mutex();\n\ndiff --git a/negotiator/default.c b/negotiator/default.c\nindex 4b78f6bf36..434189ae5d 100644\n--- a/negotiator/default.c\n+++ b/negotiator/default.c\n@@ -167,7 +167,7 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)\n \tnegotiator->next = next;\n \tnegotiator->ack = ack;\n \tnegotiator->release = release;\n-\tnegotiator->data = ns = xcalloc(1, sizeof(*ns));\n+\tnegotiator->data = CALLOC_ARRAY(ns, 1);\n \tns->rev_list.compare = compare_commits_by_commit_date;\n\n \tif (marked)\ndiff --git a/negotiator/skipping.c b/negotiator/skipping.c\nindex dffbc76c49..1236e79224 100644\n--- a/negotiator/skipping.c\n+++ b/negotiator/skipping.c\n@@ -62,7 +62,7 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int\n \tstruct entry *entry;\n \tcommit->object.flags |= mark | SEEN;\n\n-\tentry = xcalloc(1, sizeof(*entry));\n+\tCALLOC_ARRAY(entry, 1);\n \tentry->commit = commit;\n \tprio_queue_put(&data->rev_list, entry);\n\n@@ -241,7 +241,7 @@ void skipping_negotiator_init(struct fetch_negotiator *negotiator)\n \tnegotiator->next = next;\n \tnegotiator->ack = ack;\n \tnegotiator->release = release;\n-\tnegotiator->data = data = xcalloc(1, sizeof(*data));\n+\tnegotiator->data = CALLOC_ARRAY(data, 1);\n \tdata->rev_list.compare = compare;\n\n \tif (marked)\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 2fe724f1cf..d2771fa3d4 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -136,7 +136,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \tdiff_tree_oid(base, remote, \"\", &opt);\n \tdiffcore_std(&opt);\n\n-\tchanges = xcalloc(diff_queued_diff.nr, sizeof(struct notes_merge_pair));\n+\tCALLOC_ARRAY(changes, diff_queued_diff.nr);\n\n \tfor (i = 0; i < diff_queued_diff.nr; i++) {\n \t\tstruct diff_filepair *p = diff_queued_diff.queue[i];\ndiff --git a/notes-utils.c b/notes-utils.c\nindex 4bf4888d8c..d7d18e30f5 100644\n--- a/notes-utils.c\n+++ b/notes-utils.c\n@@ -129,7 +129,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)\n \tc->cmd = cmd;\n \tc->enabled = 1;\n \tc->combine = combine_notes_concatenate;\n-\tc->refs = xcalloc(1, sizeof(struct string_list));\n+\tCALLOC_ARRAY(c->refs, 1);\n \tc->refs->strdup_strings = 1;\n \tc->refs_from_env = 0;\n \tc->mode_from_env = 0;\ndiff --git a/notes.c b/notes.c\nindex d5ac081e76..a19e4ad794 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -452,7 +452,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,\n \t\t\tgoto handle_non_note;\n \t\t}\n\n-\t\tl = xcalloc(1, sizeof(*l));\n+\t\tCALLOC_ARRAY(l, 1);\n \t\toidcpy(&l->key_oid, &object_oid);\n \t\toidcpy(&l->val_oid, &entry.oid);\n \t\tif (note_tree_insert(t, node, n, l, type,\ndiff --git a/object-file.c b/object-file.c\nindex 5bcfde8471..624af408cd 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -546,7 +546,7 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,\n \t\treturn -1;\n \t}\n\n-\tent = xcalloc(1, sizeof(*ent));\n+\tCALLOC_ARRAY(ent, 1);\n \tent->path = xstrdup(pathbuf.buf);\n\n \t/* add the alternate entry */\ndiff --git a/object.c b/object.c\nindex 98017bed8e..78343781ae 100644\n--- a/object.c\n+++ b/object.c\n@@ -127,7 +127,7 @@ static void grow_object_hash(struct repository *r)\n \tint new_hash_size = r->parsed_objects->obj_hash_size < 32 ? 32 : 2 * r->parsed_objects->obj_hash_size;\n \tstruct object **new_hash;\n\n-\tnew_hash = xcalloc(new_hash_size, sizeof(struct object *));\n+\tCALLOC_ARRAY(new_hash, new_hash_size);\n \tfor (i = 0; i < r->parsed_objects->obj_hash_size; i++) {\n \t\tstruct object *obj = r->parsed_objects->obj_hash[i];\n\n@@ -478,7 +478,7 @@ struct parsed_object_pool *parsed_object_pool_new(void)\n \to->object_state = allocate_alloc_state();\n\n \to->is_shallow = -1;\n-\to->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));\n+\tCALLOC_ARRAY(o->shallow_stat, 1);\n\n \to->buffer_slab = allocate_commit_buffer_slab();\n\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 1f69b5fa85..1ebe0c8162 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -978,7 +978,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,\n\n \t/* try to open a bitmapped pack, but don't parse it yet\n \t * because we may not need to use it */\n-\tbitmap_git = xcalloc(1, sizeof(*bitmap_git));\n+\tCALLOC_ARRAY(bitmap_git, 1);\n \tif (open_pack_bitmap(revs->repo, bitmap_git) < 0)\n \t\tgoto cleanup;\n\n@@ -1388,7 +1388,7 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,\n \tuint32_t *reposition;\n\n \tnum_objects = bitmap_git->pack->num_objects;\n-\treposition = xcalloc(num_objects, sizeof(uint32_t));\n+\tCALLOC_ARRAY(reposition, num_objects);\n\n \tfor (i = 0; i < num_objects; ++i) {\n \t\tstruct object_id oid;\ndiff --git a/pack-objects.c b/pack-objects.c\nindex f2a433885a..fe2a4eace9 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -49,7 +49,7 @@ static void rehash_objects(struct packing_data *pdata)\n \t\tpdata->index_size = 1024;\n\n \tfree(pdata->index);\n-\tpdata->index = xcalloc(pdata->index_size, sizeof(*pdata->index));\n+\tCALLOC_ARRAY(pdata->index, pdata->index_size);\n\n \tentry = pdata->objects;\n\ndiff --git a/packfile.c b/packfile.c\nindex 1fec12ac5f..ea29f4ba77 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -638,7 +638,7 @@ unsigned char *use_pack(struct packed_git *p,\n \t\t\tif (p->pack_fd == -1 && open_packed_git(p))\n \t\t\t\tdie(\"packfile %s cannot be accessed\", p->pack_name);\n\n-\t\t\twin = xcalloc(1, sizeof(*win));\n+\t\t\tCALLOC_ARRAY(win, 1);\n \t\t\twin->offset = (offset / window_align) * window_align;\n \t\t\tlen = p->pack_size - win->offset;\n \t\t\tif (len > packed_git_window_size)\ndiff --git a/patch-ids.c b/patch-ids.c\nindex 3f404e4b0b..8bf425555d 100644\n--- a/patch-ids.c\n+++ b/patch-ids.c\n@@ -124,7 +124,7 @@ struct patch_id *add_commit_patch_id(struct commit *commit,\n \tif (!patch_id_defined(commit))\n \t\treturn NULL;\n\n-\tkey = xcalloc(1, sizeof(*key));\n+\tCALLOC_ARRAY(key, 1);\n \tif (init_patch_id_entry(key, commit, ids)) {\n \t\tfree(key);\n \t\treturn NULL;\ndiff --git a/pathspec.c b/pathspec.c\nindex 7a229d8d22..18b3be362a 100644\n--- a/pathspec.c\n+++ b/pathspec.c\n@@ -154,7 +154,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va\n \tstring_list_remove_empty_items(&list, 0);\n\n \titem->attr_check = attr_check_alloc();\n-\titem->attr_match = xcalloc(list.nr, sizeof(struct attr_match));\n+\tCALLOC_ARRAY(item->attr_match, list.nr);\n\n \tfor_each_string_list_item(si, &list) {\n \t\tsize_t attr_len;\n@@ -561,7 +561,7 @@ void parse_pathspec(struct pathspec *pathspec,\n \t\tif (!(flags & PATHSPEC_PREFER_CWD))\n \t\t\tBUG(\"PATHSPEC_PREFER_CWD requires arguments\");\n\n-\t\tpathspec->items = item = xcalloc(1, sizeof(*item));\n+\t\tpathspec->items = CALLOC_ARRAY(item, 1);\n \t\titem->match = xstrdup(prefix);\n \t\titem->original = xstrdup(prefix);\n \t\titem->nowildcard_len = item->len = strlen(prefix);\ndiff --git a/pretty.c b/pretty.c\nindex c5f5ecc40d..d5efd00e21 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -678,7 +678,7 @@ static int mailmap_name(const char **email, size_t *email_len,\n {\n \tstatic struct string_list *mail_map;\n \tif (!mail_map) {\n-\t\tmail_map = xcalloc(1, sizeof(*mail_map));\n+\t\tCALLOC_ARRAY(mail_map, 1);\n \t\tread_mailmap(mail_map);\n \t}\n \treturn mail_map->nr && map_user(mail_map, email, email_len, name, name_len);\ndiff --git a/progress.c b/progress.c\nindex 31014e6fca..680c6a8bf9 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -196,7 +196,7 @@ void display_throughput(struct progress *progress, uint64_t total)\n \tnow_ns = progress_getnanotime(progress);\n\n \tif (!tp) {\n-\t\tprogress->throughput = tp = xcalloc(1, sizeof(*tp));\n+\t\tprogress->throughput = CALLOC_ARRAY(tp, 1);\n \t\ttp->prev_total = tp->curr_total = total;\n \t\ttp->prev_ns = now_ns;\n \t\tstrbuf_init(&tp->display, 0);\ndiff --git a/promisor-remote.c b/promisor-remote.c\nindex 3c572b1c81..da3f2ca261 100644\n--- a/promisor-remote.c\n+++ b/promisor-remote.c\n@@ -208,7 +208,7 @@ static int remove_fetched_oids(struct repository *repo,\n\n \tif (remaining_nr) {\n \t\tint j = 0;\n-\t\tnew_oids = xcalloc(remaining_nr, sizeof(*new_oids));\n+\t\tCALLOC_ARRAY(new_oids, remaining_nr);\n \t\tfor (i = 0; i < oid_nr; i++)\n \t\t\tif (remaining[i])\n \t\t\t\toidcpy(&new_oids[j++], &old_oids[i]);\ndiff --git a/range-diff.c b/range-diff.c\nindex f617426474..116fb0735c 100644\n--- a/range-diff.c\n+++ b/range-diff.c\n@@ -96,7 +96,7 @@ static int read_patches(const char *range, struct string_list *list,\n \t\t\t\tstring_list_append(list, buf.buf)->util = util;\n \t\t\t\tstrbuf_reset(&buf);\n \t\t\t}\n-\t\t\tutil = xcalloc(1, sizeof(*util));\n+\t\t\tCALLOC_ARRAY(util, 1);\n \t\t\tif (get_oid(p, &util->oid)) {\n \t\t\t\terror(_(\"could not parse commit '%s'\"), p);\n \t\t\t\tfree(util);\ndiff --git a/read-cache.c b/read-cache.c\nindex 1e9a50c6c7..c8d12eaa3c 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -2097,7 +2097,7 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con\n \t/* ensure we have no more threads than we have blocks to process */\n \tif (nr_threads > ieot->nr)\n \t\tnr_threads = ieot->nr;\n-\tdata = xcalloc(nr_threads, sizeof(*data));\n+\tCALLOC_ARRAY(data, nr_threads);\n\n \toffset = ieot_start = 0;\n \tieot_blocks = DIV_ROUND_UP(ieot->nr, nr_threads);\n@@ -2199,7 +2199,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)\n \tistate->version = ntohl(hdr->hdr_version);\n \tistate->cache_nr = ntohl(hdr->hdr_entries);\n \tistate->cache_alloc = alloc_nr(istate->cache_nr);\n-\tistate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));\n+\tCALLOC_ARRAY(istate->cache, istate->cache_alloc);\n \tistate->initialized = 1;\n\n \tp.istate = istate;\n@@ -2326,7 +2326,7 @@ int read_index_from(struct index_state *istate, const char *path,\n \tif (split_index->base)\n \t\tdiscard_index(split_index->base);\n \telse\n-\t\tsplit_index->base = xcalloc(1, sizeof(*split_index->base));\n+\t\tCALLOC_ARRAY(split_index->base, 1);\n\n \tbase_oid_hex = oid_to_hex(&split_index->base_oid);\n \tbase_path = xstrfmt(\"%s/sharedindex.%s\", gitdir, base_oid_hex);\n@@ -3427,7 +3427,7 @@ void stat_validity_update(struct stat_validity *sv, int fd)\n \t\tstat_validity_clear(sv);\n \telse {\n \t\tif (!sv->sd)\n-\t\t\tsv->sd = xcalloc(1, sizeof(struct stat_data));\n+\t\t\tCALLOC_ARRAY(sv->sd, 1);\n \t\tfill_stat_data(sv->sd, &st);\n \t}\n }\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 33b5e68056..f0bd32f714 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1677,7 +1677,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)\n \tint i;\n \tstruct object_info empty = OBJECT_INFO_INIT;\n\n-\tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n+\tCALLOC_ARRAY(ref->value, used_atom_cnt);\n\n \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n \t\tref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,\n@@ -2186,7 +2186,7 @@ static void reach_filter(struct ref_array *array,\n \tif (!check_reachable)\n \t\treturn;\n\n-\tto_clear = xcalloc(array->nr, sizeof(struct commit *));\n+\tCALLOC_ARRAY(to_clear, array->nr);\n\n \trepo_init_revisions(the_repository, &revs, NULL);\n\n@@ -2491,7 +2491,7 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)\n {\n \tstruct ref_sorting *s;\n\n-\ts = xcalloc(1, sizeof(*s));\n+\tCALLOC_ARRAY(s, 1);\n \ts->next = *sorting_tail;\n \t*sorting_tail = s;\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex 3a25b27d8f..e9cd328369 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -112,7 +112,7 @@ struct reflog_walk_info {\n\n void init_reflog_walk(struct reflog_walk_info **info)\n {\n-\t*info = xcalloc(1, sizeof(struct reflog_walk_info));\n+\tCALLOC_ARRAY(*info, 1);\n \t(*info)->complete_reflogs.strdup_strings = 1;\n }\n\n@@ -181,7 +181,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,\n \t}\n \tfree(branch);\n\n-\tcommit_reflog = xcalloc(1, sizeof(struct commit_reflog));\n+\tCALLOC_ARRAY(commit_reflog, 1);\n \tif (recno < 0) {\n \t\tcommit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);\n \t\tif (commit_reflog->recno < 0) {\ndiff --git a/refs.c b/refs.c\nindex a665ed5e10..261fd82beb 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1007,7 +1007,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,\n \tstruct ref_transaction *tr;\n \tassert(err);\n\n-\ttr = xcalloc(1, sizeof(struct ref_transaction));\n+\tCALLOC_ARRAY(tr, 1);\n \ttr->ref_store = refs;\n \treturn tr;\n }\n@@ -1306,7 +1306,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti\n \t\twhile (len && ref[len - 1] == '/')\n \t\t\tref[--len] = '\\0';\n \t\tif (!hide_refs) {\n-\t\t\thide_refs = xcalloc(1, sizeof(*hide_refs));\n+\t\t\tCALLOC_ARRAY(hide_refs, 1);\n \t\t\thide_refs->strdup_strings = 1;\n \t\t}\n \t\tstring_list_append(hide_refs, ref);\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex 4fdc68810b..119972ee16 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -549,7 +549,7 @@ static int lock_raw_ref(struct files_ref_store *refs,\n\n \t/* First lock the file so it can't change out from under us. */\n\n-\t*lock_p = lock = xcalloc(1, sizeof(*lock));\n+\t*lock_p = CALLOC_ARRAY(lock, 1);\n\n \tlock->ref_name = xstrdup(refname);\n \tfiles_ref_path(refs, &ref_file, refname);\n@@ -843,7 +843,7 @@ static struct ref_iterator *files_ref_iterator_begin(\n\n \toverlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);\n\n-\titer = xcalloc(1, sizeof(*iter));\n+\tCALLOC_ARRAY(iter, 1);\n \tref_iterator = &iter->base;\n \tbase_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,\n \t\t\t       overlay_iter->ordered);\n@@ -930,7 +930,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,\n \tfiles_assert_main_repository(refs, \"lock_ref_oid_basic\");\n \tassert(err);\n\n-\tlock = xcalloc(1, sizeof(struct ref_lock));\n+\tCALLOC_ARRAY(lock, 1);\n\n \tif (mustexist)\n \t\tresolve_flags |= RESOLVE_REF_READING;\n@@ -2152,7 +2152,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,\n \t\treturn empty_ref_iterator_begin();\n \t}\n\n-\titer = xcalloc(1, sizeof(*iter));\n+\tCALLOC_ARRAY(iter, 1);\n \tref_iterator = &iter->base;\n\n \tbase_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0);\n@@ -2597,7 +2597,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,\n \tif (!transaction->nr)\n \t\tgoto cleanup;\n\n-\tbackend_data = xcalloc(1, sizeof(*backend_data));\n+\tCALLOC_ARRAY(backend_data, 1);\n \ttransaction->backend_data = backend_data;\n\n \t/*\ndiff --git a/refs/iterator.c b/refs/iterator.c\nindex 629e00a122..a89d132d4f 100644\n--- a/refs/iterator.c\n+++ b/refs/iterator.c\n@@ -393,7 +393,7 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,\n \tif (!*prefix && !trim)\n \t\treturn iter0; /* optimization: no need to wrap iterator */\n\n-\titer = xcalloc(1, sizeof(*iter));\n+\tCALLOC_ARRAY(iter, 1);\n \tref_iterator = &iter->base;\n\n \tbase_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable, iter0->ordered);\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex b912f2505f..dfecdbc1db 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -941,7 +941,7 @@ static struct ref_iterator *packed_ref_iterator_begin(\n \tif (start == snapshot->eof)\n \t\treturn empty_ref_iterator_begin();\n\n-\titer = xcalloc(1, sizeof(*iter));\n+\tCALLOC_ARRAY(iter, 1);\n \tref_iterator = &iter->base;\n \tbase_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1);\n\n@@ -1424,7 +1424,7 @@ static int packed_transaction_prepare(struct ref_store *ref_store,\n \t * do so itself.\n \t */\n\n-\tdata = xcalloc(1, sizeof(*data));\n+\tCALLOC_ARRAY(data, 1);\n \tstring_list_init(&data->updates, 0);\n\n \ttransaction->backend_data = data;\ndiff --git a/refs/ref-cache.c b/refs/ref-cache.c\nindex b7052f72e2..46f1e54284 100644\n--- a/refs/ref-cache.c\n+++ b/refs/ref-cache.c\n@@ -530,7 +530,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,\n \tif (prime_dir)\n \t\tprime_ref_dir(dir, prefix);\n\n-\titer = xcalloc(1, sizeof(*iter));\n+\tCALLOC_ARRAY(iter, 1);\n \tref_iterator = &iter->base;\n \tbase_ref_iterator_init(ref_iterator, &cache_ref_iterator_vtable, 1);\n \tALLOC_GROW(iter->levels, 10, iter->levels_alloc);\ndiff --git a/remote.c b/remote.c\nindex c3f85c17ca..6d1e8d02df 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -151,7 +151,7 @@ static struct remote *make_remote(const char *name, int len)\n \tif (e)\n \t\treturn container_of(e, struct remote, ent);\n\n-\tret = xcalloc(1, sizeof(struct remote));\n+\tCALLOC_ARRAY(ret, 1);\n \tret->prune = -1;  /* unspecified */\n \tret->prune_tags = -1;  /* unspecified */\n \tret->name = xstrndup(name, len);\n@@ -186,7 +186,7 @@ static struct branch *make_branch(const char *name, size_t len)\n \t}\n\n \tALLOC_GROW(branches, branches_nr + 1, branches_alloc);\n-\tret = xcalloc(1, sizeof(struct branch));\n+\tCALLOC_ARRAY(ret, 1);\n \tbranches[branches_nr++] = ret;\n \tret->name = xstrndup(name, len);\n \tret->refname = xstrfmt(\"refs/heads/%s\", ret->name);\n@@ -207,7 +207,7 @@ static struct rewrite *make_rewrite(struct rewrites *r,\n \t}\n\n \tALLOC_GROW(r->rewrite, r->rewrite_nr + 1, r->rewrite_alloc);\n-\tret = xcalloc(1, sizeof(struct rewrite));\n+\tCALLOC_ARRAY(ret, 1);\n \tr->rewrite[r->rewrite_nr++] = ret;\n \tret->base = xstrndup(base, len);\n \tret->baselen = len;\n@@ -1664,7 +1664,7 @@ static void set_merge(struct branch *ret)\n\n \tremote = remote_get(ret->remote_name);\n\n-\tret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge));\n+\tCALLOC_ARRAY(ret->merge, ret->merge_nr);\n \tfor (i = 0; i < ret->merge_nr; i++) {\n \t\tret->merge[i] = xcalloc(1, sizeof(**ret->merge));\n \t\tret->merge[i]->src = xstrdup(ret->merge_name[i]);\ndiff --git a/repository.c b/repository.c\nindex c98298acd0..87b355e7a6 100644\n--- a/repository.c\n+++ b/repository.c\n@@ -72,7 +72,7 @@ void repo_set_gitdir(struct repository *repo,\n \trepo_set_commondir(repo, o->commondir);\n\n \tif (!repo->objects->odb) {\n-\t\trepo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb));\n+\t\tCALLOC_ARRAY(repo->objects->odb, 1);\n \t\trepo->objects->odb_tail = &repo->objects->odb->next;\n \t}\n \texpand_base_dir(&repo->objects->odb->path, o->object_dir,\n@@ -262,7 +262,7 @@ void repo_clear(struct repository *repo)\n int repo_read_index(struct repository *repo)\n {\n \tif (!repo->index)\n-\t\trepo->index = xcalloc(1, sizeof(*repo->index));\n+\t\tCALLOC_ARRAY(repo->index, 1);\n\n \t/* Complete the double-reference */\n \tif (!repo->index->repo)\ndiff --git a/resolve-undo.c b/resolve-undo.c\nindex 236320f179..bbd2e57fe4 100644\n--- a/resolve-undo.c\n+++ b/resolve-undo.c\n@@ -15,7 +15,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)\n \t\treturn;\n\n \tif (!istate->resolve_undo) {\n-\t\tresolve_undo = xcalloc(1, sizeof(*resolve_undo));\n+\t\tCALLOC_ARRAY(resolve_undo, 1);\n \t\tresolve_undo->strdup_strings = 1;\n \t\tistate->resolve_undo = resolve_undo;\n \t}\n@@ -57,7 +57,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)\n \tint i;\n \tconst unsigned rawsz = the_hash_algo->rawsz;\n\n-\tresolve_undo = xcalloc(1, sizeof(*resolve_undo));\n+\tCALLOC_ARRAY(resolve_undo, 1);\n \tresolve_undo->strdup_strings = 1;\n\n \twhile (size) {\ndiff --git a/revision.c b/revision.c\nindex b78733f508..99c859f797 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -154,7 +154,7 @@ static void paths_and_oids_insert(struct hashmap *map,\n\n \tentry = hashmap_get_entry(map, &key, ent, NULL);\n \tif (!entry) {\n-\t\tentry = xcalloc(1, sizeof(struct path_and_oids_entry));\n+\t\tCALLOC_ARRAY(entry, 1);\n \t\thashmap_entry_init(&entry->ent, hash);\n \t\tentry->path = xstrdup(key.path);\n \t\toidset_init(&entry->trees, 16);\n@@ -1555,7 +1555,7 @@ void clear_ref_exclusion(struct string_list **ref_excludes_p)\n void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)\n {\n \tif (!*ref_excludes_p) {\n-\t\t*ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p));\n+\t\tCALLOC_ARRAY(*ref_excludes_p, 1);\n \t\t(*ref_excludes_p)->strdup_strings = 1;\n \t}\n \tstring_list_append(*ref_excludes_p, exclude);\n@@ -2929,7 +2929,7 @@ static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs,\n\n \tst = lookup_decoration(&revs->merge_simplification, &commit->object);\n \tif (!st) {\n-\t\tst = xcalloc(1, sizeof(*st));\n+\t\tCALLOC_ARRAY(st, 1);\n \t\tadd_decoration(&revs->merge_simplification, &commit->object, st);\n \t}\n \treturn st;\ndiff --git a/run-command.c b/run-command.c\nindex 4e34623e2e..be6bc128cd 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -1638,8 +1638,8 @@ static void pp_init(struct parallel_processes *pp,\n \tpp->nr_processes = 0;\n \tpp->output_owner = 0;\n \tpp->shutdown = 0;\n-\tpp->children = xcalloc(n, sizeof(*pp->children));\n-\tpp->pfd = xcalloc(n, sizeof(*pp->pfd));\n+\tCALLOC_ARRAY(pp->children, n);\n+\tCALLOC_ARRAY(pp->pfd, n);\n \tstrbuf_init(&pp->buffered_output, 0);\n\n \tfor (i = 0; i < n; i++) {\ndiff --git a/send-pack.c b/send-pack.c\nindex 9045f8a082..5f215b13c7 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -188,13 +188,13 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)\n \t\t\t}\n \t\t\tif (new_report) {\n \t\t\t\tif (!hint->report) {\n-\t\t\t\t\thint->report = xcalloc(1, sizeof(struct ref_push_report));\n+\t\t\t\t\tCALLOC_ARRAY(hint->report, 1);\n \t\t\t\t\treport = hint->report;\n \t\t\t\t} else {\n \t\t\t\t\treport = hint->report;\n \t\t\t\t\twhile (report->next)\n \t\t\t\t\t\treport = report->next;\n-\t\t\t\t\treport->next = xcalloc(1, sizeof(struct ref_push_report));\n+\t\t\t\t\tCALLOC_ARRAY(report->next, 1);\n \t\t\t\t\treport = report->next;\n \t\t\t\t}\n \t\t\t\tnew_report = 0;\ndiff --git a/sequencer.c b/sequencer.c\nindex d2332d3e17..848204d3dc 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -5171,7 +5171,7 @@ void todo_list_add_exec_commands(struct todo_list *todo_list,\n \tint i, insert, nr = 0, alloc = 0;\n \tstruct todo_item *items = NULL, *base_items = NULL;\n\n-\tbase_items = xcalloc(commands->nr, sizeof(struct todo_item));\n+\tCALLOC_ARRAY(base_items, commands->nr);\n \tfor (i = 0; i < commands->nr; i++) {\n \t\tsize_t command_len = strlen(commands->items[i].string);\n\ndiff --git a/server-info.c b/server-info.c\nindex bae2cdfd51..de0aa4498c 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -296,7 +296,7 @@ static void init_pack_info(const char *infofile, int force)\n\n \t\ti = num_pack++;\n \t\tALLOC_GROW(info, num_pack, alloc);\n-\t\tinfo[i] = xcalloc(1, sizeof(struct pack_info));\n+\t\tCALLOC_ARRAY(info[i], 1);\n \t\tinfo[i]->p = p;\n \t\tinfo[i]->old_num = -1;\n \t}\ndiff --git a/split-index.c b/split-index.c\nindex c0e8ad670d..94937d21a3 100644\n--- a/split-index.c\n+++ b/split-index.c\n@@ -5,7 +5,7 @@\n struct split_index *init_split_index(struct index_state *istate)\n {\n \tif (!istate->split_index) {\n-\t\tistate->split_index = xcalloc(1, sizeof(*istate->split_index));\n+\t\tCALLOC_ARRAY(istate->split_index, 1);\n \t\tistate->split_index->refcount = 1;\n \t}\n \treturn istate->split_index;\n@@ -87,7 +87,7 @@ void move_cache_to_base_index(struct index_state *istate)\n \t\tmem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);\n \t}\n\n-\tsi->base = xcalloc(1, sizeof(*si->base));\n+\tCALLOC_ARRAY(si->base, 1);\n \tsi->base->version = istate->version;\n \t/* zero timestamp disables racy test in ce_write_index() */\n \tsi->base->timestamp = istate->timestamp;\ndiff --git a/trailer.c b/trailer.c\nindex 35b58357cb..be4e972642 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -445,7 +445,7 @@ static struct arg_item *get_conf_item(const char *name)\n \t}\n\n \t/* Item does not already exists, create it */\n-\titem = xcalloc(1, sizeof(*item));\n+\tCALLOC_ARRAY(item, 1);\n \tduplicate_conf(&item->conf, &default_conf_info);\n \titem->conf.name = xstrdup(name);\n\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 49b7fb4dcb..4cd76366fa 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -745,13 +745,13 @@ static int push_update_ref_status(struct strbuf *buf,\n \t\t\tdie(_(\"'option' without a matching 'ok/error' directive\"));\n \t\tif (state->new_report) {\n \t\t\tif (!state->hint->report) {\n-\t\t\t\tstate->hint->report = xcalloc(1, sizeof(struct ref_push_report));\n+\t\t\t\tCALLOC_ARRAY(state->hint->report, 1);\n \t\t\t\tstate->report = state->hint->report;\n \t\t\t} else {\n \t\t\t\tstate->report = state->hint->report;\n \t\t\t\twhile (state->report->next)\n \t\t\t\t\tstate->report = state->report->next;\n-\t\t\t\tstate->report->next = xcalloc(1, sizeof(struct ref_push_report));\n+\t\t\t\tCALLOC_ARRAY(state->report->next, 1);\n \t\t\t\tstate->report = state->report->next;\n \t\t\t}\n \t\t\tstate->new_report = 0;\ndiff --git a/transport.c b/transport.c\nindex b13fab5dc3..1c4ab676d1 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -871,7 +871,7 @@ void transport_take_over(struct transport *transport,\n \t\tBUG(\"taking over transport requires non-NULL \"\n \t\t    \"smart_options field.\");\n\n-\tdata = xcalloc(1, sizeof(*data));\n+\tCALLOC_ARRAY(data, 1);\n \tdata->options = *transport->smart_options;\n \tdata->conn = child;\n \tdata->fd[0] = data->conn->out;\ndiff --git a/worktree.c b/worktree.c\nindex e00858540e..f35ac40a84 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -53,7 +53,7 @@ static struct worktree *get_main_worktree(void)\n \tstrbuf_add_real_path(&worktree_path, get_git_common_dir());\n \tstrbuf_strip_suffix(&worktree_path, \"/.git\");\n\n-\tworktree = xcalloc(1, sizeof(*worktree));\n+\tCALLOC_ARRAY(worktree, 1);\n \tworktree->path = strbuf_detach(&worktree_path, NULL);\n \t/*\n \t * NEEDSWORK: If this function is called from a secondary worktree and\n@@ -84,7 +84,7 @@ static struct worktree *get_linked_worktree(const char *id)\n \tstrbuf_rtrim(&worktree_path);\n \tstrbuf_strip_suffix(&worktree_path, \"/.git\");\n\n-\tworktree = xcalloc(1, sizeof(*worktree));\n+\tCALLOC_ARRAY(worktree, 1);\n \tworktree->path = strbuf_detach(&worktree_path, NULL);\n \tworktree->id = xstrdup(id);\n \tadd_head_info(worktree);\ndiff --git a/wt-status.c b/wt-status.c\nindex 0c8287a023..1aed68c43c 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -456,7 +456,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,\n \t\tit = string_list_insert(&s->change, p->two->path);\n \t\td = it->util;\n \t\tif (!d) {\n-\t\t\td = xcalloc(1, sizeof(*d));\n+\t\t\tCALLOC_ARRAY(d, 1);\n \t\t\tit->util = d;\n \t\t}\n \t\tif (!d->worktree_status)\n@@ -540,7 +540,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,\n \t\tit = string_list_insert(&s->change, p->two->path);\n \t\td = it->util;\n \t\tif (!d) {\n-\t\t\td = xcalloc(1, sizeof(*d));\n+\t\t\tCALLOC_ARRAY(d, 1);\n \t\t\tit->util = d;\n \t\t}\n \t\tif (!d->index_status)\n@@ -671,7 +671,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)\n \t\tit = string_list_insert(&s->change, ce->name);\n \t\td = it->util;\n \t\tif (!d) {\n-\t\t\td = xcalloc(1, sizeof(*d));\n+\t\t\tCALLOC_ARRAY(d, 1);\n \t\t\tit->util = d;\n \t\t}\n \t\tif (ce_stage(ce)) {\n--\n2.30.2\n"},{"id":"419200","messageId":"48772615-4b68-724f-dae6-4153aafbde35@web.de","threadId":"55306","inReplyTo":"xmqq35ww1amf.fsf@gitster.g","subject":"Re: [PATCH 2/2] use CALLOC_ARRAY","fromName":"René Scharfe.","fromEmail":"l.s.r@web.de","sentAt":"2021-03-15T22:35:03Z","receivedAt":"2021-03-15T22:35:50Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 15.03.21 um 20:26 schrieb Junio C Hamano:\n> https://github.com/git/git/runs/2114848725?check_suite_focus=true\n> tells us that we want to be using CALLOC_ARRAY() instead of\n> xcalloc() at these places.\n>\n> Quite a many are single-element allocations that want NUL-filled\n> piece of memory.  We may want to resurrect the \"one-element calloc\n> is exempt\" thing (in other words, xcalloc(1, size_of_one_element) is\n> perfectly fine, even though xcalloc(size_of_one_element, 1) must\n> swap the order of arguments).\n\nLeaving the idiomatic use of xcalloc for allocating a single cleared\nobject alone can make sense.  CALLOC_ARRAY with a single element\nmight become idiomatic over time as well, though, but with \"C\" (for\ncontinuous) and \"ARRAY\" having two name parts screaming for multiple\nelements might be a bit much.\n\n> But some are true multi-element allocations that we may want to fix\n> in each topic in flight.\n>\n> compat/simple-ipc/ipc-unix-socket.c::836\n>     1e7cdcb6 (simple-ipc: add Unix domain socket implementation, 2021-03-09)\n>\n> merge-strategies.c::498\n>     72a74644 (merge-octopus: rewrite in C, 2020-11-24)\n>\n> t/helper/test-bloom.c::72\n>     f1294eaf (bloom.c: introduce core Bloom filter constructs, 2020-03-30)\n>\n>\n> Also there are a few multi-element allocations that are old, which\n> weren't somehow caught by the patch I am responding to.\n\nWhen I run coccicheck agains seen it still misses the following\nconversions:\n\n builtin/checkout.c                  |    2 +-\n builtin/log.c                       |    4 ++--\n builtin/receive-pack.c              |   10 ++++------\n t/helper/test-bloom.c               |    2 +-\n\nThat's with spatch built from the latest Coccinelle source as of March\n2nd.  Strange.\n\n>\n> builtin/receive-pack.c::2351\n>     0a1bc12b (receive-pack: allow pushes that update .git/shallow, 2013-12-05)\n>\n> ----- >8 ---------- >8 ---------- >8 ---------- >8 ---------- >8 -----\n>\n> GIT_VERSION = 2.31.0.rc2.390.g46dd778bfd\n>     SPATCH contrib/coccinelle/hashmap.cocci\n>     SPATCH contrib/coccinelle/commit.cocci\n>     SPATCH contrib/coccinelle/xcalloc.cocci\n>     SPATCH contrib/coccinelle/preincr.cocci\n>     SPATCH contrib/coccinelle/free.cocci\n>     SPATCH contrib/coccinelle/qsort.cocci\n>     SPATCH contrib/coccinelle/object_id.cocci\n>     SPATCH contrib/coccinelle/xstrdup_or_null.cocci\n>     SPATCH contrib/coccinelle/swap.cocci\n>     SPATCH contrib/coccinelle/strbuf.cocci\n>     SPATCH contrib/coccinelle/flex_alloc.cocci\n>     SPATCH contrib/coccinelle/array.cocci\n>      SPATCH result: contrib/coccinelle/array.cocci.patch\n> + set +x\n> Coccinelle suggests the following changes in 'contrib/coccinelle/array.cocci.patch':\n> diff -u -p a/builtin/checkout.c b/builtin/checkout.c\n> --- a/builtin/checkout.c\n> +++ b/builtin/checkout.c\n> @@ -741,7 +741,7 @@ static int merge_working_tree(const stru\n>  \t\t\t\t       &new_branch_info->commit->object.oid :\n>  \t\t\t\t       &new_branch_info->oid, NULL);\n>  \t\tif (opts->overwrite_ignore) {\n> -\t\t\ttopts.dir = xcalloc(1, sizeof(*topts.dir));\n> +\t\t\tCALLOC_ARRAY(topts.dir, 1);\n>  \t\t\ttopts.dir->flags |= DIR_SHOW_IGNORED;\n>  \t\t\tsetup_standard_excludes(topts.dir);\n>  \t\t}\n> diff -u -p a/builtin/log.c b/builtin/log.c\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -230,7 +230,7 @@ static void cmd_log_init_finish(int argc\n>  \t}\n>\n>  \tif (mailmap) {\n> -\t\trev->mailmap = xcalloc(1, sizeof(struct string_list));\n> +\t\tCALLOC_ARRAY(rev->mailmap, 1);\n>  \t\tread_mailmap(rev->mailmap);\n>  \t}\n>\n> @@ -2141,7 +2141,7 @@ int cmd_format_patch(int argc, const cha\n>  \t}\n>\n>  \tif (in_reply_to || thread || cover_letter)\n> -\t\trev.ref_message_ids = xcalloc(1, sizeof(struct string_list));\n> +\t\tCALLOC_ARRAY(rev.ref_message_ids, 1);\n>  \tif (in_reply_to) {\n>  \t\tconst char *msgid = clean_message_id(in_reply_to);\n>  \t\tstring_list_append(rev.ref_message_ids, msgid);\n> diff -u -p a/builtin/receive-pack.c b/builtin/receive-pack.c\n> --- a/builtin/receive-pack.c\n> +++ b/builtin/receive-pack.c\n> @@ -1040,7 +1040,7 @@ static int read_proc_receive_report(stru\n>  \t\t\t\t\treport = hint->report;\n>  \t\t\t\t\twhile (report->next)\n>  \t\t\t\t\t\treport = report->next;\n> -\t\t\t\t\treport->next = xcalloc(1, sizeof(struct ref_push_report));\n> +\t\t\t\t\tCALLOC_ARRAY(report->next, 1);\n>  \t\t\t\t\treport = report->next;\n>  \t\t\t\t}\n>  \t\t\t\tnew_report = 0;\n> @@ -2348,11 +2348,9 @@ static void prepare_shallow_update(struc\n>  \tALLOC_ARRAY(si->used_shallow, si->shallow->nr);\n>  \tassign_shallow_commits_to_refs(si, si->used_shallow, NULL);\n>\n> -\tsi->need_reachability_test =\n> -\t\txcalloc(si->shallow->nr, sizeof(*si->need_reachability_test));\n> -\tsi->reachable =\n> -\t\txcalloc(si->shallow->nr, sizeof(*si->reachable));\n> -\tsi->shallow_ref = xcalloc(si->ref->nr, sizeof(*si->shallow_ref));\n> +\tCALLOC_ARRAY(si->need_reachability_test, si->shallow->nr);\n> +\tCALLOC_ARRAY(si->reachable, si->shallow->nr);\n> +\tCALLOC_ARRAY(si->shallow_ref, si->ref->nr);\n>\n>  \tfor (i = 0; i < si->nr_ours; i++)\n>  \t\tsi->need_reachability_test[si->ours[i]] = 1;\n> diff -u -p a/builtin/repack.c b/builtin/repack.c\n> --- a/builtin/repack.c\n> +++ b/builtin/repack.c\n> @@ -327,7 +327,7 @@ static void init_pack_geometry(struct pa\n>  \tstruct packed_git *p;\n>  \tstruct pack_geometry *geometry;\n>\n> -\t*geometry_p = xcalloc(1, sizeof(struct pack_geometry));\n> +\tCALLOC_ARRAY(*geometry_p, 1);\n>  \tgeometry = *geometry_p;\n>\n>  \tfor (p = get_all_packs(the_repository); p; p = p->next) {\n> diff -u -p a/compat/simple-ipc/ipc-unix-socket.c b/compat/simple-ipc/ipc-unix-socket.c\n> --- a/compat/simple-ipc/ipc-unix-socket.c\n> +++ b/compat/simple-ipc/ipc-unix-socket.c\n> @@ -130,7 +130,7 @@ enum ipc_active_state ipc_client_try_con\n>  \ttrace2_region_leave(\"ipc-client\", \"try-connect\", NULL);\n>\n>  \tif (state == IPC_STATE__LISTENING) {\n> -\t\t(*p_connection) = xcalloc(1, sizeof(struct ipc_client_connection));\n> +\t\tCALLOC_ARRAY((*p_connection), 1);\n>  \t\t(*p_connection)->fd = fd;\n>  \t}\n>\n> @@ -819,7 +819,7 @@ int ipc_server_run_async(struct ipc_serv\n>  \t\treturn ret;\n>  \t}\n>\n> -\tserver_data = xcalloc(1, sizeof(*server_data));\n> +\tCALLOC_ARRAY(server_data, 1);\n>  \tserver_data->magic = MAGIC_SERVER_DATA;\n>  \tserver_data->application_cb = application_cb;\n>  \tserver_data->application_data = application_data;\n> @@ -833,11 +833,9 @@ int ipc_server_run_async(struct ipc_serv\n>  \tpthread_cond_init(&server_data->work_available_cond, NULL);\n>\n>  \tserver_data->queue_size = nr_threads * FIFO_SCALE;\n> -\tserver_data->fifo_fds = xcalloc(server_data->queue_size,\n> -\t\t\t\t\tsizeof(*server_data->fifo_fds));\n> +\tCALLOC_ARRAY(server_data->fifo_fds, server_data->queue_size);\n>\n> -\tserver_data->accept_thread =\n> -\t\txcalloc(1, sizeof(*server_data->accept_thread));\n> +\tCALLOC_ARRAY(server_data->accept_thread, 1);\n>  \tserver_data->accept_thread->magic = MAGIC_ACCEPT_THREAD_DATA;\n>  \tserver_data->accept_thread->server_data = server_data;\n>  \tserver_data->accept_thread->server_socket = server_socket;\n> @@ -851,7 +849,7 @@ int ipc_server_run_async(struct ipc_serv\n>  \tfor (k = 0; k < nr_threads; k++) {\n>  \t\tstruct ipc_worker_thread_data *wtd;\n>\n> -\t\twtd = xcalloc(1, sizeof(*wtd));\n> +\t\tCALLOC_ARRAY(wtd, 1);\n>  \t\twtd->magic = MAGIC_WORKER_THREAD_DATA;\n>  \t\twtd->server_data = server_data;\n>\n> diff -u -p a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c\n> --- a/compat/simple-ipc/ipc-win32.c\n> +++ b/compat/simple-ipc/ipc-win32.c\n> @@ -184,7 +184,7 @@ enum ipc_active_state ipc_client_try_con\n>  \ttrace2_region_leave(\"ipc-client\", \"try-connect\", NULL);\n>\n>  \tif (state == IPC_STATE__LISTENING) {\n> -\t\t(*p_connection) = xcalloc(1, sizeof(struct ipc_client_connection));\n> +\t\tCALLOC_ARRAY((*p_connection), 1);\n>  \t\t(*p_connection)->fd = fd;\n>  \t}\n>\n> @@ -625,7 +625,7 @@ int ipc_server_run_async(struct ipc_serv\n>  \t\treturn -2;\n>  \t}\n>\n> -\tserver_data = xcalloc(1, sizeof(*server_data));\n> +\tCALLOC_ARRAY(server_data, 1);\n>  \tserver_data->magic = MAGIC_SERVER_DATA;\n>  \tserver_data->application_cb = application_cb;\n>  \tserver_data->application_data = application_data;\n> @@ -640,7 +640,7 @@ int ipc_server_run_async(struct ipc_serv\n>  \tfor (k = 0; k < nr_threads; k++) {\n>  \t\tstruct ipc_server_thread_data *std;\n>\n> -\t\tstd = xcalloc(1, sizeof(*std));\n> +\t\tCALLOC_ARRAY(std, 1);\n>  \t\tstd->magic = MAGIC_SERVER_THREAD_DATA;\n>  \t\tstd->server_data = server_data;\n>  \t\tstd->hPipe = INVALID_HANDLE_VALUE;\n> diff -u -p a/merge-ort.c b/merge-ort.c\n> --- a/merge-ort.c\n> +++ b/merge-ort.c\n> @@ -3439,7 +3439,7 @@ static void merge_start(struct merge_opt\n>  \t\ttrace2_region_leave(\"merge\", \"allocate/init\", opt->repo);\n>  \t\treturn;\n>  \t}\n> -\topt->priv = xcalloc(1, sizeof(*opt->priv));\n> +\tCALLOC_ARRAY(opt->priv, 1);\n>\n>  \t/* Initialization of various renames fields */\n>  \trenames = &opt->priv->renames;\n> diff -u -p a/merge-strategies.c b/merge-strategies.c\n> --- a/merge-strategies.c\n> +++ b/merge-strategies.c\n> @@ -495,8 +495,7 @@ int merge_strategies_octopus(struct repo\n>  \t\treturn 2;\n>  \t}\n>\n> -\treference_commit = xcalloc(commit_list_count(remotes) + 1,\n> -\t\t\t\t   sizeof(struct commit *));\n> +\tCALLOC_ARRAY(reference_commit, commit_list_count(remotes) + 1);\n>  \treference_commit[0] = head_commit;\n>  \treference_tree = head_tree;\n>\n> diff -u -p a/t/helper/test-bloom.c b/t/helper/test-bloom.c\n> --- a/t/helper/test-bloom.c\n> +++ b/t/helper/test-bloom.c\n> @@ -69,7 +69,7 @@ int cmd__bloom(int argc, const char **ar\n>  \t\tstruct bloom_filter filter;\n>  \t\tint i = 2;\n>  \t\tfilter.len =  (settings.bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;\n> -\t\tfilter.data = xcalloc(filter.len, sizeof(unsigned char));\n> +\t\tCALLOC_ARRAY(filter.data, filter.len);\n>\n>  \t\tif (argc - 1 < i)\n>  \t\t\tusage(bloom_usage);\n> diff -u -p a/unix-stream-server.c b/unix-stream-server.c\n> --- a/unix-stream-server.c\n> +++ b/unix-stream-server.c\n> @@ -72,7 +72,7 @@ int unix_stream_server__create(\n>  \t\treturn -1;\n>  \t}\n>\n> -\tserver_socket = xcalloc(1, sizeof(*server_socket));\n> +\tCALLOC_ARRAY(server_socket, 1);\n>  \tserver_socket->path_socket = strdup(path);\n>  \tserver_socket->fd_socket = fd_socket;\n>  \tlstat(path, &server_socket->st_socket);\n> error: Coccinelle suggested some changes\n> Error: Process completed with exit code 1.\n>\n"},{"id":"419222","messageId":"xmqqft0vzzm9.fsf_-_@gitster.g","threadId":"55306","inReplyTo":"xmqqk0q8ynz0.fsf@gitster.g","subject":"[PATCH] xcalloc: use CALLOC_ARRAY() when applicable","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-03-16T00:55:10Z","receivedAt":"2021-03-16T00:56:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"These are for codebase before Git 2.31\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * In addition to fixes to topics in flight, I found these in the\n   codebase dating as far back as 2.27 days.\n\n builtin/receive-pack.c | 8 +++-----\n t/helper/test-bloom.c  | 2 +-\n 2 files changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex ea3d0f01af..6a66687e28 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1837,11 +1837,9 @@ static void prepare_shallow_update(struct shallow_info *si)\n \tALLOC_ARRAY(si->used_shallow, si->shallow->nr);\n \tassign_shallow_commits_to_refs(si, si->used_shallow, NULL);\n \n-\tsi->need_reachability_test =\n-\t\txcalloc(si->shallow->nr, sizeof(*si->need_reachability_test));\n-\tsi->reachable =\n-\t\txcalloc(si->shallow->nr, sizeof(*si->reachable));\n-\tsi->shallow_ref = xcalloc(si->ref->nr, sizeof(*si->shallow_ref));\n+\tCALLOC_ARRAY(si->need_reachability_test, si->shallow->nr);\n+\tCALLOC_ARRAY(si->reachable, si->shallow->nr);\n+\tCALLOC_ARRAY(si->shallow_ref, si->ref->nr);\n \n \tfor (i = 0; i < si->nr_ours; i++)\n \t\tsi->need_reachability_test[si->ours[i]] = 1;\ndiff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c\nindex f0aa80b98e..eb7c011ca6 100644\n--- a/t/helper/test-bloom.c\n+++ b/t/helper/test-bloom.c\n@@ -65,7 +65,7 @@ int cmd__bloom(int argc, const char **argv)\n \t\tstruct bloom_filter filter;\n \t\tint i = 2;\n \t\tfilter.len =  (settings.bits_per_entry + BITS_PER_WORD - 1) / BITS_PER_WORD;\n-\t\tfilter.data = xcalloc(filter.len, sizeof(unsigned char));\n+\t\tCALLOC_ARRAY(filter.data, filter.len);\n \n \t\tif (argc - 1 < i)\n \t\t\tusage(bloom_usage);\n-- \n2.31.0-186-g100f68d7d5\n\n"},{"id":"419296","messageId":"311a844d-a174-3e22-a7f1-3339e00e5241@gmail.com","threadId":"55306","inReplyTo":"xmqqft0vzzm9.fsf_-_@gitster.g","subject":"Re: [PATCH] xcalloc: use CALLOC_ARRAY() when applicable","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2021-03-16T11:43:02Z","receivedAt":"2021-03-16T11:43:59Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 3/15/2021 8:55 PM, Junio C Hamano wrote:\n> These are for codebase before Git 2.31\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>  * In addition to fixes to topics in flight, I found these in the\n>    codebase dating as far back as 2.27 days.\n\nThanks for catching these items. LGTM.\n\n-Stolee\n"}]}