]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use CALLOC_ARRAY
authorRené Scharfe <l.s.r@web.de>
Sat, 13 Mar 2021 16:17:22 +0000 (17:17 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 14 Mar 2021 00:00:09 +0000 (16:00 -0800)
Add and apply a semantic patch for converting code that open-codes
CALLOC_ARRAY to use it instead.  It shortens the code and infers the
element size automatically.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
88 files changed:
add-interactive.c
apply.c
archive-tar.c
attr.c
bisect.c
blame.c
bloom.c
builtin/clean.c
builtin/fast-import.c
builtin/grep.c
builtin/index-pack.c
builtin/ls-remote.c
builtin/merge.c
builtin/notes.c
builtin/pack-objects.c
builtin/pack-redundant.c
builtin/receive-pack.c
builtin/unpack-objects.c
bulk-checkin.c
cache-tree.c
combine-diff.c
commit-graph.c
commit-reach.c
commit.c
config.c
contrib/coccinelle/array.cocci
convert.c
daemon.c
decorate.c
diff.c
diffcore-rename.c
dir.c
ewah/bitmap.c
fetch-pack.c
fmt-merge-msg.c
grep.c
hashmap.c
http-backend.c
http-push.c
http.c
imap-send.c
line-log.c
line-range.c
list-objects-filter.c
ll-merge.c
mailmap.c
merge-ort.c
merge-recursive.c
midx.c
name-hash.c
negotiator/default.c
negotiator/skipping.c
notes-merge.c
notes-utils.c
notes.c
object-file.c
object.c
pack-bitmap.c
pack-objects.c
packfile.c
patch-ids.c
pathspec.c
pretty.c
progress.c
promisor-remote.c
range-diff.c
read-cache.c
ref-filter.c
reflog-walk.c
refs.c
refs/files-backend.c
refs/iterator.c
refs/packed-backend.c
refs/ref-cache.c
remote.c
repository.c
resolve-undo.c
revision.c
run-command.c
send-pack.c
sequencer.c
server-info.c
split-index.c
trailer.c
transport-helper.c
transport.c
worktree.c
wt-status.c

index 9b8cdb4a31a6ab69e7bb4e698782b11764c094c7..1f3f8f72f86ad6076d770a1cad82dc0526b58221 100644 (file)
@@ -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);
+                       CALLOC_ARRAY(entry, 1);
                        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;
diff --git a/apply.c b/apply.c
index 668b16e9893d2f1e0501f2771716138db6e2efdd..6695a931e979a968b28af88d425d0c76ba17d0d4 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -1781,7 +1781,7 @@ static int parse_single_patch(struct apply_state *state,
                struct fragment *fragment;
                int len;
 
-               fragment = xcalloc(1, sizeof(*fragment));
+               CALLOC_ARRAY(fragment, 1);
                fragment->linenr = state->linenr;
                len = parse_fragment(state, line, size, patch, fragment);
                if (len <= 0) {
@@ -1959,7 +1959,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,
                size -= llen;
        }
 
-       frag = xcalloc(1, sizeof(*frag));
+       CALLOC_ARRAY(frag, 1);
        frag->patch = inflate_it(data, hunk_size, origlen);
        frag->free_patch = 1;
        if (!frag->patch)
@@ -4681,7 +4681,7 @@ static int apply_patch(struct apply_state *state,
                struct patch *patch;
                int nr;
 
-               patch = xcalloc(1, sizeof(*patch));
+               CALLOC_ARRAY(patch, 1);
                patch->inaccurate_eof = !!(options & APPLY_OPT_INACCURATE_EOF);
                patch->recount =  !!(options & APPLY_OPT_RECOUNT);
                nr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch);
index a971fdc0f6326e0829225d4a2bfe87df48b82a42..05d2455870d7fa95f2575a35a81c3cbe7363e625 100644 (file)
@@ -371,7 +371,7 @@ static int tar_filter_config(const char *var, const char *value, void *data)
 
        ar = find_tar_filter(name, namelen);
        if (!ar) {
-               ar = xcalloc(1, sizeof(*ar));
+               CALLOC_ARRAY(ar, 1);
                ar->name = xmemdupz(name, namelen);
                ar->write_archive = write_tar_filter_archive;
                ar->flags = ARCHIVER_WANT_COMPRESSION_LEVELS |
diff --git a/attr.c b/attr.c
index 4ef85d668b54960d692b6bae127920c10045c4ca..59a8d8af1ae821223dd70fc61949406f1a384e4c 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -569,7 +569,7 @@ struct attr_check *attr_check_initl(const char *one, ...)
        check = attr_check_alloc();
        check->nr = cnt;
        check->alloc = cnt;
-       check->items = xcalloc(cnt, sizeof(struct attr_check_item));
+       CALLOC_ARRAY(check->items, cnt);
 
        check->items[0].attr = git_attr(one);
        va_start(params, one);
@@ -670,7 +670,7 @@ static struct attr_stack *read_attr_from_array(const char **list)
        const char *line;
        int lineno = 0;
 
-       res = xcalloc(1, sizeof(*res));
+       CALLOC_ARRAY(res, 1);
        while ((line = *(list++)) != NULL)
                handle_attr_line(res, line, "[builtin]", ++lineno, 1);
        return res;
@@ -707,7 +707,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
 
        if (!fp)
                return NULL;
-       res = xcalloc(1, sizeof(*res));
+       CALLOC_ARRAY(res, 1);
        while (fgets(buf, sizeof(buf), fp)) {
                char *bufp = buf;
                if (!lineno)
@@ -733,7 +733,7 @@ static struct attr_stack *read_attr_from_index(const struct index_state *istate,
        if (!buf)
                return NULL;
 
-       res = xcalloc(1, sizeof(*res));
+       CALLOC_ARRAY(res, 1);
        for (sp = buf; *sp; ) {
                char *ep;
                int more;
@@ -774,7 +774,7 @@ static struct attr_stack *read_attr(const struct index_state *istate,
        }
 
        if (!res)
-               res = xcalloc(1, sizeof(*res));
+               CALLOC_ARRAY(res, 1);
        return res;
 }
 
@@ -874,7 +874,7 @@ static void bootstrap_attr_stack(const struct index_state *istate,
        else
                e = NULL;
        if (!e)
-               e = xcalloc(1, sizeof(struct attr_stack));
+               CALLOC_ARRAY(e, 1);
        push_stack(stack, e, NULL, 0);
 }
 
index ae48d19acf6c70b97790edca0aca36d63d87f0da..af2863d044b704f3b7e9d6617dbb2226d4c8a1fe 100644 (file)
--- a/bisect.c
+++ b/bisect.c
@@ -423,7 +423,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
        show_list("bisection 2 sorted", 0, nr, list);
 
        *all = nr;
-       weights = xcalloc(on_list, sizeof(*weights));
+       CALLOC_ARRAY(weights, on_list);
 
        /* Do the real work of finding bisection commit. */
        best = do_find_bisection(list, nr, weights, bisect_flags);
diff --git a/blame.c b/blame.c
index a5044fcfaa62644daa45103dd6ad17647bc6a811..5018bb8fb2ce810f18f7e57ab26c659b6f943745 100644 (file)
--- a/blame.c
+++ b/blame.c
@@ -951,13 +951,13 @@ static int *fuzzy_find_matching_lines(struct blame_origin *parent,
        max_search_distance_b = ((2 * max_search_distance_a + 1) * length_b
                                 - 1) / length_a;
 
-       result = xcalloc(sizeof(int), length_b);
-       second_best_result = xcalloc(sizeof(int), length_b);
-       certainties = xcalloc(sizeof(int), length_b);
+       CALLOC_ARRAY(result, length_b);
+       CALLOC_ARRAY(second_best_result, length_b);
+       CALLOC_ARRAY(certainties, length_b);
 
        /* See get_similarity() for details of similarities. */
        similarity_count = length_b * (max_search_distance_a * 2 + 1);
-       similarities = xcalloc(sizeof(int), similarity_count);
+       CALLOC_ARRAY(similarities, similarity_count);
 
        for (i = 0; i < length_b; ++i) {
                result[i] = -1;
@@ -995,7 +995,7 @@ static void fill_origin_fingerprints(struct blame_origin *o)
                return;
        o->num_lines = find_line_starts(&line_starts, o->file.ptr,
                                        o->file.size);
-       o->fingerprints = xcalloc(sizeof(struct fingerprint), o->num_lines);
+       CALLOC_ARRAY(o->fingerprints, o->num_lines);
        get_line_fingerprints(o->fingerprints, o->file.ptr, line_starts,
                              0, o->num_lines);
        free(line_starts);
@@ -1853,8 +1853,7 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
        diffp = NULL;
 
        if (ignore_diffs && same - tlno > 0) {
-               line_blames = xcalloc(sizeof(struct blame_line_tracker),
-                                     same - tlno);
+               CALLOC_ARRAY(line_blames, same - tlno);
                guess_line_blames(parent, target, tlno, offset, same,
                                  parent_len, line_blames);
        }
@@ -2216,7 +2215,7 @@ static struct blame_list *setup_blame_list(struct blame_entry *unblamed,
        for (e = unblamed, num_ents = 0; e; e = e->next)
                num_ents++;
        if (num_ents) {
-               blame_list = xcalloc(num_ents, sizeof(struct blame_list));
+               CALLOC_ARRAY(blame_list, num_ents);
                for (e = unblamed, i = 0; e; e = e->next)
                        blame_list[i++].ent = e;
        }
@@ -2428,7 +2427,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
        else if (num_sg < ARRAY_SIZE(sg_buf))
                memset(sg_buf, 0, sizeof(sg_buf));
        else
-               sg_origin = xcalloc(num_sg, sizeof(*sg_origin));
+               CALLOC_ARRAY(sg_origin, num_sg);
 
        /*
         * The first pass looks for unrenamed path to optimize for
diff --git a/bloom.c b/bloom.c
index b176f28f531eccc412204faa5f4da9fa53164081..52b87474c6eb5a3d257c3f597f5340b893fb33c0 100644 (file)
--- a/bloom.c
+++ b/bloom.c
@@ -277,7 +277,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
                                *computed |= BLOOM_TRUNC_EMPTY;
                        filter->len = 1;
                }
-               filter->data = xcalloc(filter->len, sizeof(unsigned char));
+               CALLOC_ARRAY(filter->data, filter->len);
 
                hashmap_for_each_entry(&pathmap, &iter, e, entry) {
                        struct bloom_key key;
index 687ab473c20c6bee7d578a8650cc906fa3e70184..995053b79173e1eab3d4ce567557c37893f4214a 100644 (file)
@@ -623,7 +623,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
                                nr += chosen[i];
                }
 
-               result = xcalloc(st_add(nr, 1), sizeof(int));
+               CALLOC_ARRAY(result, st_add(nr, 1));
                for (i = 0; i < stuff->nr && j < nr; i++) {
                        if (chosen[i])
                                result[j++] = i;
index dd4d09cecebd57a6d89c3b8224a5435f26c5a5d2..3afa81cf9acdba53ef6ddaa30b54e5ae539f745d 100644 (file)
@@ -3322,7 +3322,7 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)
                die(_("Expected format name:filename for submodule rewrite option"));
        *f = '\0';
        f++;
-       ms = xcalloc(1, sizeof(*ms));
+       CALLOC_ARRAY(ms, 1);
 
        fp = fopen(f, "r");
        if (!fp)
@@ -3519,9 +3519,9 @@ int cmd_fast_import(int argc, const char **argv, const char *prefix)
 
        alloc_objects(object_entry_alloc);
        strbuf_init(&command_buf, 0);
-       atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
-       branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
-       avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
+       CALLOC_ARRAY(atom_table, atom_table_sz);
+       CALLOC_ARRAY(branch_table, branch_table_sz);
+       CALLOC_ARRAY(avail_tree_table, avail_tree_table_sz);
        marks = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set));
 
        hashmap_init(&object_table, object_entry_hashcmp, NULL, 0);
index 4e91a253ac3b5fd0cdbd0436018c82fb45bde04c..ccd8d08f3dd4992dff5c837b064a63c1f5d94a8c 100644 (file)
@@ -211,7 +211,7 @@ static void start_threads(struct grep_opt *opt)
                strbuf_init(&todo[i].out, 0);
        }
 
-       threads = xcalloc(num_threads, sizeof(*threads));
+       CALLOC_ARRAY(threads, num_threads);
        for (i = 0; i < num_threads; i++) {
                int err;
                struct grep_opt *o = grep_opt_dup(opt);
index bad57488079c7f7ec715f9efd935e255c871e8f1..21899687e2ceb6700ce3bdee50a1bf9887c569d3 100644 (file)
@@ -185,7 +185,7 @@ static void init_thread(void)
        if (show_stat)
                pthread_mutex_init(&deepest_delta_mutex, NULL);
        pthread_key_create(&key, NULL);
-       thread_data = xcalloc(nr_threads, sizeof(*thread_data));
+       CALLOC_ARRAY(thread_data, nr_threads);
        for (i = 0; i < nr_threads; i++) {
                thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
                if (thread_data[i].pack_fd == -1)
@@ -1674,7 +1674,7 @@ static void show_pack_info(int stat_only)
        unsigned long *chain_histogram = NULL;
 
        if (deepest_delta)
-               chain_histogram = xcalloc(deepest_delta, sizeof(unsigned long));
+               CALLOC_ARRAY(chain_histogram, deepest_delta);
 
        for (i = 0; i < nr_objects; i++) {
                struct object_entry *obj = &objects[i];
@@ -1912,10 +1912,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
 
        curr_pack = open_pack_file(pack_name);
        parse_pack_header();
-       objects = xcalloc(st_add(nr_objects, 1), sizeof(struct object_entry));
+       CALLOC_ARRAY(objects, st_add(nr_objects, 1));
        if (show_stat)
-               obj_stat = xcalloc(st_add(nr_objects, 1), sizeof(struct object_stat));
-       ofs_deltas = xcalloc(nr_objects, sizeof(struct ofs_delta_entry));
+               CALLOC_ARRAY(obj_stat, st_add(nr_objects, 1));
+       CALLOC_ARRAY(ofs_deltas, nr_objects);
        parse_pack_objects(pack_hash);
        if (report_end_of_input)
                write_in_full(2, "\0", 1);
index ef604752a044a48609a10ee90a8ca487c0acfb2d..abfa9847374fdd861e454d12b1e68e874016c3e6 100644 (file)
@@ -88,7 +88,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
        if (argc > 1) {
                int i;
-               pattern = xcalloc(argc, sizeof(const char *));
+               CALLOC_ARRAY(pattern, argc);
                for (i = 1; i < argc; i++) {
                        pattern[i - 1] = xstrfmt("*/%s", argv[i]);
                }
index eb00b273e668e2725447a2d6a0edc5ad2d67ed67..388619536aa1d250d6cad275b67974bbfdca28e4 100644 (file)
@@ -210,7 +210,7 @@ static struct strategy *get_strategy(const char *name)
                exit(1);
        }
 
-       ret = xcalloc(1, sizeof(struct strategy));
+       CALLOC_ARRAY(ret, 1);
        ret->name = xstrdup(name);
        ret->attr = NO_TRIVIAL;
        return ret;
index 08b8914d299517013395063704d36556fd9435df..74bba39ca8293208d3d577a47e2617a11d856c20 100644 (file)
@@ -730,7 +730,7 @@ static int merge_commit(struct notes_merge_options *o)
        else
                oidclr(&parent_oid);
 
-       t = xcalloc(1, sizeof(struct notes_tree));
+       CALLOC_ARRAY(t, 1);
        init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
 
        o->local_ref = local_ref_to_free =
index 6d62aaf59a030de6845dd1d27c9e9fa9421267b9..4bb602688c1231ccdd661164d925b2922ceecb8b 100644 (file)
@@ -1635,7 +1635,7 @@ static void add_preferred_base(struct object_id *oid)
                }
        }
 
-       it = xcalloc(1, sizeof(*it));
+       CALLOC_ARRAY(it, 1);
        it->next = pbase_tree;
        pbase_tree = it;
 
@@ -2096,7 +2096,7 @@ static void get_object_details(void)
                progress_state = start_progress(_("Counting objects"),
                                                to_pack.nr_objects);
 
-       sorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *));
+       CALLOC_ARRAY(sorted_by_offset, to_pack.nr_objects);
        for (i = 0; i < to_pack.nr_objects; i++)
                sorted_by_offset[i] = to_pack.objects + i;
        QSORT(sorted_by_offset, to_pack.nr_objects, pack_offset_sort);
@@ -2428,7 +2428,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
        struct unpacked *array;
        unsigned long mem_usage = 0;
 
-       array = xcalloc(window, sizeof(struct unpacked));
+       CALLOC_ARRAY(array, window);
 
        for (;;) {
                struct object_entry *entry;
@@ -2665,7 +2665,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
        if (progress > pack_to_stdout)
                fprintf_ln(stderr, _("Delta compression using up to %d threads"),
                           delta_search_threads);
-       p = xcalloc(delta_search_threads, sizeof(*p));
+       CALLOC_ARRAY(p, delta_search_threads);
 
        /* Partition the work amongst work threads. */
        for (i = 0; i < delta_search_threads; i++) {
index 6e115a811aa29ecb97df0ad81810df77ec16e57b..7102996c75e7e73466f46e26ae08bfc5dc4b0c5b 100644 (file)
@@ -373,7 +373,7 @@ static void sort_pack_list(struct pack_list **pl)
                return;
 
        /* prepare an array of packed_list for easier sorting */
-       ary = xcalloc(n, sizeof(struct pack_list *));
+       CALLOC_ARRAY(ary, n);
        for (n = 0, p = *pl; p; p = p->next)
                ary[n++] = p;
 
index d26040c477924826a4d24fe4efdded74278c8684..51c8c40fab3bb54e51293295503a792685f4a46b 100644 (file)
@@ -358,7 +358,7 @@ static void proc_receive_ref_append(const char *prefix)
        char *p;
        int len;
 
-       ref_pattern = xcalloc(1, sizeof(struct proc_receive_ref));
+       CALLOC_ARRAY(ref_pattern, 1);
        p = strchr(prefix, ':');
        if (p) {
                while (prefix < p) {
@@ -1024,7 +1024,7 @@ static int read_proc_receive_report(struct packet_reader *reader,
                        }
                        if (new_report) {
                                if (!hint->report) {
-                                       hint->report = xcalloc(1, sizeof(struct ref_push_report));
+                                       CALLOC_ARRAY(hint->report, 1);
                                        report = hint->report;
                                } else {
                                        report = hint->report;
index dd4a75e030d219dfb3e5e0eeb59683c14f02fdf0..a4ba2ebac692d9844fe328361133885c095ceb24 100644 (file)
@@ -46,7 +46,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base)
 static void add_object_buffer(struct object *object, char *buffer, unsigned long size)
 {
        struct obj_buffer *obj;
-       obj = xcalloc(1, sizeof(struct obj_buffer));
+       CALLOC_ARRAY(obj, 1);
        obj->buffer = buffer;
        obj->size = size;
        if (add_decoration(&obj_decorate, object, obj))
@@ -500,7 +500,7 @@ static void unpack_all(void)
 
        if (!quiet)
                progress = start_progress(_("Unpacking objects"), nr_objects);
-       obj_list = xcalloc(nr_objects, sizeof(*obj_list));
+       CALLOC_ARRAY(obj_list, nr_objects);
        for (i = 0; i < nr_objects; i++) {
                unpack_one(i);
                display_progress(progress, i + 1);
index 583aacb9e36bded9047d5f18219637ba1613a612..6f3c97cd347b5989521c01d62b0dc01c67ebe355 100644 (file)
@@ -211,7 +211,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
 
        /* Note: idx is non-NULL when we are writing */
        if ((flags & HASH_WRITE_OBJECT) != 0)
-               idx = xcalloc(1, sizeof(*idx));
+               CALLOC_ARRAY(idx, 1);
 
        already_hashed_to = 0;
 
index 2fb483d3c0838998677d53327100db7bc134e2f3..add1f077131768414301fedaa3fefa9fa9ddbb45 100644 (file)
@@ -564,7 +564,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
         * hence +2.
         */
        it->subtree_alloc = subtree_nr + 2;
-       it->down = xcalloc(it->subtree_alloc, sizeof(struct cache_tree_sub *));
+       CALLOC_ARRAY(it->down, it->subtree_alloc);
        for (i = 0; i < subtree_nr; i++) {
                /* read each subtree */
                struct cache_tree *sub;
index 9228aebc16b698886a712a1c1c7381176ca158c1..06635f91bc21a54a5e7bfa4355c2d8e4b536f257 100644 (file)
@@ -214,11 +214,11 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
         *   - Else if we have NEW, insert newend lline into base and
         *   consume newend
         */
-       lcs = xcalloc(st_add(origbaselen, 1), sizeof(int*));
-       directions = xcalloc(st_add(origbaselen, 1), sizeof(enum coalesce_direction*));
+       CALLOC_ARRAY(lcs, st_add(origbaselen, 1));
+       CALLOC_ARRAY(directions, st_add(origbaselen, 1));
        for (i = 0; i < origbaselen + 1; i++) {
-               lcs[i] = xcalloc(st_add(lennew, 1), sizeof(int));
-               directions[i] = xcalloc(st_add(lennew, 1), sizeof(enum coalesce_direction));
+               CALLOC_ARRAY(lcs[i], st_add(lennew, 1));
+               CALLOC_ARRAY(directions[i], st_add(lennew, 1));
                directions[i][0] = BASE;
        }
        for (j = 1; j < lennew + 1; j++)
@@ -398,8 +398,8 @@ static void consume_hunk(void *state_,
                state->lost_bucket = &state->sline[state->nb-1];
        }
        if (!state->sline[state->nb-1].p_lno)
-               state->sline[state->nb-1].p_lno =
-                       xcalloc(state->num_parent, sizeof(unsigned long));
+               CALLOC_ARRAY(state->sline[state->nb - 1].p_lno,
+                            state->num_parent);
        state->sline[state->nb-1].p_lno[state->n] = state->ob;
 }
 
@@ -1159,7 +1159,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        if (result_size && result[result_size-1] != '\n')
                cnt++; /* incomplete line */
 
-       sline = xcalloc(st_add(cnt, 2), sizeof(*sline));
+       CALLOC_ARRAY(sline, st_add(cnt, 2));
        sline[0].bol = result;
        for (lno = 0, cp = result; cp < result + result_size; cp++) {
                if (*cp == '\n') {
@@ -1178,7 +1178,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
        /* Even p_lno[cnt+1] is valid -- that is for the end line number
         * for deletion hunk at the end.
         */
-       sline[0].p_lno = xcalloc(st_mult(st_add(cnt, 2), num_parent), sizeof(unsigned long));
+       CALLOC_ARRAY(sline[0].p_lno, st_mult(st_add(cnt, 2), num_parent));
        for (lno = 0; lno <= cnt; lno++)
                sline[lno+1].p_lno = sline[lno].p_lno + num_parent;
 
@@ -1319,7 +1319,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
        struct diff_filespec *pool;
 
        pair = xmalloc(sizeof(*pair));
-       pool = xcalloc(st_add(num_parent, 1), sizeof(struct diff_filespec));
+       CALLOC_ARRAY(pool, st_add(num_parent, 1));
        pair->one = pool + 1;
        pair->two = pool;
 
@@ -1348,7 +1348,7 @@ static void handle_combined_callback(struct diff_options *opt,
        struct diff_queue_struct q;
        int i;
 
-       q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));
+       CALLOC_ARRAY(q.queue, num_paths);
        q.alloc = num_paths;
        q.nr = num_paths;
        for (i = 0, p = paths; p; p = p->next)
index ca025ce8eb561181fb450e607c50cf3d9dc448cb..e21eeea42b96d5cd20b62b031def7aebe2a96272 100644 (file)
@@ -516,7 +516,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
                return NULL;
 
        count = st.st_size / (the_hash_algo->hexsz + 1);
-       oids = xcalloc(count, sizeof(struct object_id));
+       CALLOC_ARRAY(oids, count);
 
        prepare_alt_odb(r);
 
@@ -2238,7 +2238,7 @@ int write_commit_graph(struct object_directory *odb,
        if (!commit_graph_compatible(the_repository))
                return 0;
 
-       ctx = xcalloc(1, sizeof(struct write_commit_graph_context));
+       CALLOC_ARRAY(ctx, 1);
        ctx->r = the_repository;
        ctx->odb = odb;
        ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
index 2ea84d3dc0747bc906a0d9534046a99c877e4d18..c226ee3da469c50c82dea58804ad3819230ed112 100644 (file)
@@ -183,7 +183,7 @@ static int remove_redundant_no_gen(struct repository *r,
        int *filled_index;
        int i, j, filled;
 
-       work = xcalloc(cnt, sizeof(*work));
+       CALLOC_ARRAY(work, cnt);
        redundant = xcalloc(cnt, 1);
        ALLOC_ARRAY(filled_index, cnt - 1);
 
@@ -399,7 +399,7 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
 
        /* There are more than one */
        cnt = commit_list_count(result);
-       rslt = xcalloc(cnt, sizeof(*rslt));
+       CALLOC_ARRAY(rslt, cnt);
        for (list = result, i = 0; list; list = list->next)
                rslt[i++] = list->item;
        free_commit_list(result);
@@ -541,7 +541,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
                p->item->object.flags |= STALE;
                num_head++;
        }
-       array = xcalloc(num_head, sizeof(*array));
+       CALLOC_ARRAY(array, num_head);
        for (p = heads, i = 0; p; p = p->next) {
                if (p->item->object.flags & STALE) {
                        array[i++] = p->item;
index 6ccd774841c6939eb977696ac6f30c04dd514ce3..42f8117b51e2b680d1e323741fe503fc4299682e 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -1171,7 +1171,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
         * if (verify_signed_buffer(buf, len, buf + len, size - len, ...))
         *      warn("warning: signed tag unverified.");
         */
-       mergetag = xcalloc(1, sizeof(*mergetag));
+       CALLOC_ARRAY(mergetag, 1);
        mergetag->key = xstrdup("mergetag");
        mergetag->value = buf;
        mergetag->len = size;
@@ -1336,7 +1336,7 @@ static struct commit_extra_header *read_commit_extra_header_lines(
                         excluded_header_field(line, eof - line, exclude))
                        continue;
 
-               it = xcalloc(1, sizeof(*it));
+               CALLOC_ARRAY(it, 1);
                it->key = xmemdupz(line, eof-line);
                *tail = it;
                tail = &it->next;
index f90b633dba21f3cf63698e62170dab15e316e3e5..6428393a4143b7cd9060e31dea039b639b5db22d 100644 (file)
--- a/config.c
+++ b/config.c
@@ -2269,7 +2269,7 @@ static void repo_read_config(struct repository *repo)
        opts.git_dir = repo->gitdir;
 
        if (!repo->config)
-               repo->config = xcalloc(1, sizeof(struct config_set));
+               CALLOC_ARRAY(repo->config, 1);
        else
                git_configset_clear(repo->config);
 
index 46b8d2ee11151b97e4e0cfd56afcf059247d1c54..9a17d2a121445b8b5c60843eb2620427ffb97c80 100644 (file)
@@ -88,3 +88,11 @@ expression n;
 @@
 - ptr = xmalloc((n) * sizeof(T));
 + ALLOC_ARRAY(ptr, n);
+
+@@
+type T;
+T *ptr;
+expression n;
+@@
+- ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) )
++ CALLOC_ARRAY(ptr, n)
index ee360c2f07ced0daa8f3f7b1b651fae7c245cb26..9ecc1c699c087ecc270d7a45c11f6a8b9a183201 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -1028,7 +1028,7 @@ static int read_convert_config(const char *var, const char *value, void *cb)
                if (!strncmp(drv->name, name, namelen) && !drv->name[namelen])
                        break;
        if (!drv) {
-               drv = xcalloc(1, sizeof(struct convert_driver));
+               CALLOC_ARRAY(drv, 1);
                drv->name = xmemdupz(name, namelen);
                *user_convert_tail = drv;
                user_convert_tail = &(drv->next);
index 2ab7ea82eb0b4f7c62c553e1e65c16644983f7de..343531980dea11fc15b927c67542fe6ad5f11a3d 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -840,7 +840,7 @@ static void add_child(struct child_process *cld, struct sockaddr *addr, socklen_
 {
        struct child *newborn, **cradle;
 
-       newborn = xcalloc(1, sizeof(*newborn));
+       CALLOC_ARRAY(newborn, 1);
        live_children++;
        memcpy(&newborn->cld, cld, sizeof(*cld));
        memcpy(&newborn->address, addr, addrlen);
@@ -1148,7 +1148,7 @@ static int service_loop(struct socketlist *socklist)
        struct pollfd *pfd;
        int i;
 
-       pfd = xcalloc(socklist->nr, sizeof(struct pollfd));
+       CALLOC_ARRAY(pfd, socklist->nr);
 
        for (i = 0; i < socklist->nr; i++) {
                pfd[i].fd = socklist->list[i];
index a605b1b5f4ac7844693919ca8afee3a699d1b424..2036d15967125303effff870a45066710ef99e3e 100644 (file)
@@ -39,7 +39,7 @@ static void grow_decoration(struct decoration *n)
        struct decoration_entry *old_entries = n->entries;
 
        n->size = (old_size + 1000) * 3 / 2;
-       n->entries = xcalloc(n->size, sizeof(struct decoration_entry));
+       CALLOC_ARRAY(n->entries, n->size);
        n->nr = 0;
 
        for (i = 0; i < old_size; i++) {
diff --git a/diff.c b/diff.c
index 6956f5e335c235d0a1a2ea6d8b7b8e7b7678deda..4acccd9d7edbb9e097a1d5b8b3bc2ff0ebf3acdb 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -2233,14 +2233,12 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
        struct diff_options *o = xmalloc(sizeof(struct diff_options));
        memcpy(o, orig_opts, sizeof(struct diff_options));
 
-       ecbdata->diff_words =
-               xcalloc(1, sizeof(struct diff_words_data));
+       CALLOC_ARRAY(ecbdata->diff_words, 1);
        ecbdata->diff_words->type = o->word_diff;
        ecbdata->diff_words->opt = o;
 
        if (orig_opts->emitted_symbols)
-               o->emitted_symbols =
-                       xcalloc(1, sizeof(struct emitted_diff_symbols));
+               CALLOC_ARRAY(o->emitted_symbols, 1);
 
        if (!o->word_regex)
                o->word_regex = userdiff_word_regex(one, o->repo->index);
@@ -2509,7 +2507,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
                                          const char *name_b)
 {
        struct diffstat_file *x;
-       x = xcalloc(1, sizeof(*x));
+       CALLOC_ARRAY(x, 1);
        ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
        diffstat->files[diffstat->nr++] = x;
        if (name_b) {
@@ -4918,7 +4916,7 @@ static int diff_opt_find_object(const struct option *option,
                return error(_("unable to resolve '%s'"), arg);
 
        if (!opt->objfind)
-               opt->objfind = xcalloc(1, sizeof(*opt->objfind));
+               CALLOC_ARRAY(opt->objfind, 1);
 
        opt->pickaxe_opts |= DIFF_PICKAXE_KIND_OBJFIND;
        opt->flags.recursive = 1;
index 41558185ae1d940cc74d348a00a00d5e641a5f4c..9c1478c078b3c884ca3f7f5734d4b1c424dbc1fb 100644 (file)
@@ -787,8 +787,7 @@ void diffcore_rename(struct diff_options *options)
                                (uint64_t)num_destinations * (uint64_t)num_sources);
        }
 
-       mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_destinations),
-                    sizeof(*mx));
+       CALLOC_ARRAY(mx, st_mult(NUM_CANDIDATE_PER_DST, num_destinations));
        for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
                struct diff_filespec *two = rename_dst[i].p->two;
                struct diff_score *m;
diff --git a/dir.c b/dir.c
index fd8aa7c40faa28b08a15d64438b9121402f41a55..19c2fa239b3d92c4e9cc44dfcdca72240b9dc4a0 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1488,7 +1488,7 @@ static void prep_exclude(struct dir_struct *dir,
                const char *cp;
                struct oid_stat oid_stat;
 
-               stk = xcalloc(1, sizeof(*stk));
+               CALLOC_ARRAY(stk, 1);
                if (current < 0) {
                        cp = base;
                        current = 0;
@@ -3162,7 +3162,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
        int varint_len;
        const unsigned hashsz = the_hash_algo->rawsz;
 
-       ouc = xcalloc(1, sizeof(*ouc));
+       CALLOC_ARRAY(ouc, 1);
        stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
        stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
        ouc->dir_flags = htonl(untracked->dir_flags);
@@ -3373,7 +3373,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
        if (next + exclude_per_dir_offset + 1 > end)
                return NULL;
 
-       uc = xcalloc(1, sizeof(*uc));
+       CALLOC_ARRAY(uc, 1);
        strbuf_init(&uc->ident, ident_len);
        strbuf_add(&uc->ident, ident, ident_len);
        load_oid_stat(&uc->ss_info_exclude,
index 0d31cdc866c77dfaab69b39305213497c49a120d..38a47c44db4c6cd43bd384890ed414d4665bf456 100644 (file)
@@ -25,7 +25,7 @@
 struct bitmap *bitmap_word_alloc(size_t word_alloc)
 {
        struct bitmap *bitmap = xmalloc(sizeof(struct bitmap));
-       bitmap->words = xcalloc(word_alloc, sizeof(eword_t));
+       CALLOC_ARRAY(bitmap->words, word_alloc);
        bitmap->word_alloc = word_alloc;
        return bitmap;
 }
index 6a61a464283e108915d216fb12828e06c8538f58..fb04a76ca263042b145b40adf1577a81c6d7e12d 100644 (file)
@@ -1916,7 +1916,7 @@ static void update_shallow(struct fetch_pack_args *args,
         * remote is also shallow, check what ref is safe to update
         * without updating .git/shallow
         */
-       status = xcalloc(nr_sought, sizeof(*status));
+       CALLOC_ARRAY(status, nr_sought);
        assign_shallow_commits_to_refs(si, NULL, status);
        if (si->nr_ours || si->nr_theirs) {
                for (i = 0; i < nr_sought; i++)
index 1e51492a05085f4e76bed5a32d72a6e2049b1271..0f66818e0f839f08cf5cc46cb6943f6542c4208b 100644 (file)
@@ -130,7 +130,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
        if (!find_merge_parent(merge_parents, &oid, NULL))
                return 0; /* subsumed by other parents */
 
-       origin_data = xcalloc(1, sizeof(struct origin_data));
+       CALLOC_ARRAY(origin_data, 1);
        oidcpy(&origin_data->oid, &oid);
 
        if (line[len - 1] == '\n')
diff --git a/grep.c b/grep.c
index aabfaaa4c32e48569805dbe631db64fcf7b773c6..223035318b1f5cc8d2d55e37794e9f652b7a08fc 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -621,7 +621,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
        case GREP_PATTERN: /* atom */
        case GREP_PATTERN_HEAD:
        case GREP_PATTERN_BODY:
-               x = xcalloc(1, sizeof (struct grep_expr));
+               CALLOC_ARRAY(x, 1);
                x->node = GREP_NODE_ATOM;
                x->u.atom = p;
                *list = p->next;
@@ -651,7 +651,7 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
                if (!p->next)
                        die("--not not followed by pattern expression");
                *list = p->next;
-               x = xcalloc(1, sizeof (struct grep_expr));
+               CALLOC_ARRAY(x, 1);
                x->node = GREP_NODE_NOT;
                x->u.unary = compile_pattern_not(list);
                if (!x->u.unary)
@@ -676,7 +676,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
                y = compile_pattern_and(list);
                if (!y)
                        die("--and not followed by pattern expression");
-               z = xcalloc(1, sizeof (struct grep_expr));
+               CALLOC_ARRAY(z, 1);
                z->node = GREP_NODE_AND;
                z->u.binary.left = x;
                z->u.binary.right = y;
@@ -696,7 +696,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
                y = compile_pattern_or(list);
                if (!y)
                        die("not a pattern expression %s", p->pattern);
-               z = xcalloc(1, sizeof (struct grep_expr));
+               CALLOC_ARRAY(z, 1);
                z->node = GREP_NODE_OR;
                z->u.binary.left = x;
                z->u.binary.right = y;
index 5009471800e8c61b50bfd670a7714daaa26a01c7..134d2eec804c2eb4851689901f47c251f73b01de 100644 (file)
--- a/hashmap.c
+++ b/hashmap.c
@@ -76,7 +76,7 @@ unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
 static void alloc_table(struct hashmap *map, unsigned int size)
 {
        map->tablesize = size;
-       map->table = xcalloc(size, sizeof(struct hashmap_entry *));
+       CALLOC_ARRAY(map->table, size);
 
        /* calculate resize thresholds for new size */
        map->grow_at = (unsigned int) ((uint64_t) size * HASHMAP_LOAD_FACTOR / 100);
index a03b4bae2221fc2cdb8fa5dad0f89c1ce33af281..b329bf63f097fadda16cbd4c8e1c06134b28d6a8 100644 (file)
@@ -39,7 +39,7 @@ static struct string_list *get_parameters(void)
        if (!query_params) {
                const char *query = getenv("QUERY_STRING");
 
-               query_params = xcalloc(1, sizeof(*query_params));
+               CALLOC_ARRAY(query_params, 1);
                while (query && *query) {
                        char *name = url_decode_parameter_name(&query);
                        char *value = url_decode_parameter_value(&query);
index 6a4a43e07f2cd43ad3b34b409de69d1903fb6fd9..b60d5fcc85dd18f9a6747d662c0c039d0362f982 100644 (file)
@@ -896,7 +896,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
        curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
        curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
 
-       lock = xcalloc(1, sizeof(*lock));
+       CALLOC_ARRAY(lock, 1);
        lock->timeout = -1;
 
        if (start_active_slot(slot)) {
@@ -1713,7 +1713,7 @@ int cmd_main(int argc, const char **argv)
        int new_refs;
        struct ref *ref, *local_refs;
 
-       repo = xcalloc(1, sizeof(*repo));
+       CALLOC_ARRAY(repo, 1);
 
        argv++;
        for (i = 1; i < argc; i++, argv++) {
diff --git a/http.c b/http.c
index f8ea28bb2ed2bd7189378c2a39c9f222964081cd..0e31fc21bc9cc7e135cb5b3e884a373391ea4018 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2324,7 +2324,7 @@ struct http_pack_request *new_direct_http_pack_request(
        off_t prev_posn = 0;
        struct http_pack_request *preq;
 
-       preq = xcalloc(1, sizeof(*preq));
+       CALLOC_ARRAY(preq, 1);
        strbuf_init(&preq->tmpfile, 0);
 
        preq->url = url;
@@ -2419,7 +2419,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
        off_t prev_posn = 0;
        struct http_object_request *freq;
 
-       freq = xcalloc(1, sizeof(*freq));
+       CALLOC_ARRAY(freq, 1);
        strbuf_init(&freq->tmpfile, 0);
        oidcpy(&freq->oid, oid);
        freq->localfile = -1;
index d0b94f911eebfb23389ecd2e6e24f182ddb4e57e..bb085d66d10509214eae1994e430d6058955f7cf 100644 (file)
@@ -963,9 +963,9 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
        char *arg, *rsp;
        int s = -1, preauth;
 
-       ctx = xcalloc(1, sizeof(*ctx));
+       CALLOC_ARRAY(ctx, 1);
 
-       ctx->imap = imap = xcalloc(1, sizeof(*imap));
+       ctx->imap = CALLOC_ARRAY(imap, 1);
        imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;
        imap->in_progress_append = &imap->in_progress;
 
index 75c8b1acfff86508614321a83989e2940fc21d4b..51d93310a4dee18ccfb559803583500ec45b27b4 100644 (file)
@@ -296,7 +296,7 @@ static void line_log_data_insert(struct line_log_data **list,
                return;
        }
 
-       p = xcalloc(1, sizeof(struct line_log_data));
+       CALLOC_ARRAY(p, 1);
        p->path = path;
        range_set_append(&p->ranges, begin, end);
        if (ip) {
index 9b50583dc05147fb6940c1d551ba274702704f07..955a8a9535575fe0a397497d765f3e0e97334259 100644 (file)
@@ -202,7 +202,7 @@ static const char *parse_range_funcname(
        drv = userdiff_find_by_path(istate, path);
        if (drv && drv->funcname.pattern) {
                const struct userdiff_funcname *pe = &drv->funcname;
-               xecfg = xcalloc(1, sizeof(*xecfg));
+               CALLOC_ARRAY(xecfg, 1);
                xdiff_set_find_func(xecfg, pe->pattern, pe->cflags);
        }
 
index 4ec0041cfb4eca9efc4420373ad5312569fb615c..39e2f15333694933468f6af9bea6d9804251dfcb 100644 (file)
@@ -186,7 +186,7 @@ static enum list_objects_filter_result filter_trees_depth(
                seen_info = oidmap_get(
                        &filter_data->seen_at_depth, &obj->oid);
                if (!seen_info) {
-                       seen_info = xcalloc(1, sizeof(*seen_info));
+                       CALLOC_ARRAY(seen_info, 1);
                        oidcpy(&seen_info->base.oid, &obj->oid);
                        seen_info->depth = filter_data->current_depth;
                        oidmap_put(&filter_data->seen_at_depth, seen_info);
@@ -626,7 +626,7 @@ static void filter_combine__init(
        size_t sub;
 
        d->nr = filter_options->sub_nr;
-       d->sub = xcalloc(d->nr, sizeof(*d->sub));
+       CALLOC_ARRAY(d->sub, d->nr);
        for (sub = 0; sub < d->nr; sub++)
                d->sub[sub].filter = list_objects_filter__init(
                        filter->omits ? &d->sub[sub].omits : NULL,
@@ -674,7 +674,7 @@ struct filter *list_objects_filter__init(
        if (!init_fn)
                return NULL;
 
-       filter = xcalloc(1, sizeof(*filter));
+       CALLOC_ARRAY(filter, 1);
        filter->omits = omitted;
        init_fn(filter_options, filter);
        return filter;
index 1ec0b959e015b20442aaddc417952f7a7a731d42..9a8a2c365c7a33fbf1fb4b1a50505ea19fe5558d 100644 (file)
@@ -268,7 +268,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
                if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
                        break;
        if (!fn) {
-               fn = xcalloc(1, sizeof(struct ll_merge_driver));
+               CALLOC_ARRAY(fn, 1);
                fn->name = xmemdupz(name, namelen);
                fn->fn = ll_ext_merge;
                *ll_user_merge_tail = fn;
index 9bb9cf8b3038aa8234accc4832178ee498062c59..183a2f65ee98d53704ee35ae1ec76f44b679a406 100644 (file)
--- a/mailmap.c
+++ b/mailmap.c
@@ -83,7 +83,7 @@ static void add_mapping(struct string_list *map,
        if (item->util) {
                me = (struct mailmap_entry *)item->util;
        } else {
-               me = xcalloc(1, sizeof(struct mailmap_entry));
+               CALLOC_ARRAY(me, 1);
                me->namemap.strdup_strings = 1;
                me->namemap.cmp = namemap_cmp;
                item->util = me;
index 603d30c521702ab25eae20efeda57bf1d4bea1d7..92dea35e57a856571882cb250d058f03554197c9 100644 (file)
@@ -1576,8 +1576,7 @@ static void compute_collisions(struct strmap *collisions,
                if (collision_info) {
                        free(new_path);
                } else {
-                       collision_info = xcalloc(1,
-                                                sizeof(struct collision_info));
+                       CALLOC_ARRAY(collision_info, 1);
                        string_list_init(&collision_info->source_files, 0);
                        strmap_put(collisions, new_path, collision_info);
                }
@@ -1718,7 +1717,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
                struct conflict_info *dir_ci;
                char *cur_dir = dirs_to_insert.items[i].string;
 
-               dir_ci = xcalloc(1, sizeof(*dir_ci));
+               CALLOC_ARRAY(dir_ci, 1);
 
                dir_ci->merged.directory_name = parent_name;
                len = strlen(parent_name);
@@ -2703,7 +2702,7 @@ static void process_entry(struct merge_options *opt,
                 * the directory to remain here, so we need to move this
                 * path to some new location.
                 */
-               new_ci = xcalloc(1, sizeof(*new_ci));
+               CALLOC_ARRAY(new_ci, 1);
                /* We don't really want new_ci->merged.result copied, but it'll
                 * be overwritten below so it doesn't matter.  We also don't
                 * want any directory mode/oid values copied, but we'll zero
@@ -3083,7 +3082,7 @@ static int checkout(struct merge_options *opt,
        unpack_opts.verbose_update = (opt->verbosity > 2);
        unpack_opts.fn = twoway_merge;
        if (1/* FIXME: opts->overwrite_ignore*/) {
-               unpack_opts.dir = xcalloc(1, sizeof(*unpack_opts.dir));
+               CALLOC_ARRAY(unpack_opts.dir, 1);
                unpack_opts.dir->flags |= DIR_SHOW_IGNORED;
                setup_standard_excludes(unpack_opts.dir);
        }
index b052974f191cd82741475a019076c90e45d6d4de..b69e694d986ac8f0a3e5f13f35ef81da474dade9 100644 (file)
@@ -303,7 +303,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
                return;
        }
 
-       ci = xcalloc(1, sizeof(struct rename_conflict_info));
+       CALLOC_ARRAY(ci, 1);
        ci->rename_type = rename_type;
        ci->ren1 = ren1;
        ci->ren2 = ren2;
@@ -2389,8 +2389,7 @@ static void compute_collisions(struct hashmap *collisions,
                        continue;
                collision_ent = collision_find_entry(collisions, new_path);
                if (!collision_ent) {
-                       collision_ent = xcalloc(1,
-                                               sizeof(struct collision_entry));
+                       CALLOC_ARRAY(collision_ent, 1);
                        hashmap_entry_init(&collision_ent->ent,
                                                strhash(new_path));
                        hashmap_put(collisions, &collision_ent->ent);
@@ -2594,7 +2593,7 @@ static struct string_list *get_renames(struct merge_options *opt,
        struct string_list *renames;
 
        compute_collisions(&collisions, dir_renames, pairs);
-       renames = xcalloc(1, sizeof(struct string_list));
+       CALLOC_ARRAY(renames, 1);
 
        for (i = 0; i < pairs->nr; ++i) {
                struct string_list_item *item;
@@ -3664,7 +3663,7 @@ static int merge_start(struct merge_options *opt, struct tree *head)
                return -1;
        }
 
-       opt->priv = xcalloc(1, sizeof(*opt->priv));
+       CALLOC_ARRAY(opt->priv, 1);
        string_list_init(&opt->priv->df_conflict_file_set, 1);
        return 0;
 }
diff --git a/midx.c b/midx.c
index 971faa8cfc2f6e956933b26b29bbe76d4168be1f..becfafe65e8029d4381b7302cf9644096f45f293 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -145,8 +145,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
 
        m->num_objects = ntohl(m->chunk_oid_fanout[255]);
 
-       m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
-       m->packs = xcalloc(m->num_packs, sizeof(*m->packs));
+       CALLOC_ARRAY(m->pack_names, m->num_packs);
+       CALLOC_ARRAY(m->packs, m->num_packs);
 
        cur_pack_name = (const char *)m->chunk_pack_names;
        for (i = 0; i < m->num_packs; i++) {
@@ -1144,7 +1144,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
        if (!m)
                return 0;
 
-       count = xcalloc(m->num_packs, sizeof(uint32_t));
+       CALLOC_ARRAY(count, m->num_packs);
 
        if (flags & MIDX_PROGRESS)
                progress = start_delayed_progress(_("Counting referenced objects"),
@@ -1315,7 +1315,7 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
        if (!m)
                return 0;
 
-       include_pack = xcalloc(m->num_packs, sizeof(unsigned char));
+       CALLOC_ARRAY(include_pack, m->num_packs);
 
        if (batch_size) {
                if (fill_included_packs_batch(r, m, include_pack, batch_size))
index 4e03fac9bb12599d897cc54c7154eceab267784d..ce28f3f070827faf84891c2af18e85d3ee58e565 100644 (file)
@@ -225,7 +225,7 @@ static void init_dir_mutex(void)
 {
        int j;
 
-       lazy_dir_mutex_array = xcalloc(LAZY_MAX_MUTEX, sizeof(pthread_mutex_t));
+       CALLOC_ARRAY(lazy_dir_mutex_array, LAZY_MAX_MUTEX);
 
        for (j = 0; j < LAZY_MAX_MUTEX; j++)
                init_recursive_mutex(&lazy_dir_mutex_array[j]);
@@ -514,9 +514,9 @@ static void threaded_lazy_init_name_hash(
        k_start = 0;
        nr_each = DIV_ROUND_UP(istate->cache_nr, lazy_nr_dir_threads);
 
-       lazy_entries = xcalloc(istate->cache_nr, sizeof(struct lazy_entry));
-       td_dir = xcalloc(lazy_nr_dir_threads, sizeof(struct lazy_dir_thread_data));
-       td_name = xcalloc(1, sizeof(struct lazy_name_thread_data));
+       CALLOC_ARRAY(lazy_entries, istate->cache_nr);
+       CALLOC_ARRAY(td_dir, lazy_nr_dir_threads);
+       CALLOC_ARRAY(td_name, 1);
 
        init_dir_mutex();
 
index 4b78f6bf36a0479a55934a6e4ac4c288775217f5..434189ae5dc64a2b6bbdac01d82f4f284f9855c6 100644 (file)
@@ -167,7 +167,7 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)
        negotiator->next = next;
        negotiator->ack = ack;
        negotiator->release = release;
-       negotiator->data = ns = xcalloc(1, sizeof(*ns));
+       negotiator->data = CALLOC_ARRAY(ns, 1);
        ns->rev_list.compare = compare_commits_by_commit_date;
 
        if (marked)
index dffbc76c49ef791eaba0145094bfca31b46d0913..1236e7922484a2d9b98c0d87fb0973c0b6aa6587 100644 (file)
@@ -62,7 +62,7 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int
        struct entry *entry;
        commit->object.flags |= mark | SEEN;
 
-       entry = xcalloc(1, sizeof(*entry));
+       CALLOC_ARRAY(entry, 1);
        entry->commit = commit;
        prio_queue_put(&data->rev_list, entry);
 
@@ -241,7 +241,7 @@ void skipping_negotiator_init(struct fetch_negotiator *negotiator)
        negotiator->next = next;
        negotiator->ack = ack;
        negotiator->release = release;
-       negotiator->data = data = xcalloc(1, sizeof(*data));
+       negotiator->data = CALLOC_ARRAY(data, 1);
        data->rev_list.compare = compare;
 
        if (marked)
index 2fe724f1cf8dc3cc333b9f2aa122452feac27c2c..d2771fa3d43ced4980a9c94af2ee8d5f92caa168 100644 (file)
@@ -136,7 +136,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
        diff_tree_oid(base, remote, "", &opt);
        diffcore_std(&opt);
 
-       changes = xcalloc(diff_queued_diff.nr, sizeof(struct notes_merge_pair));
+       CALLOC_ARRAY(changes, diff_queued_diff.nr);
 
        for (i = 0; i < diff_queued_diff.nr; i++) {
                struct diff_filepair *p = diff_queued_diff.queue[i];
index 4bf4888d8c1f2c1b6a08ae75dd6dcd10a8814d1d..d7d18e30f5a281278aa87fd64a4e47da8410a5eb 100644 (file)
@@ -129,7 +129,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
        c->cmd = cmd;
        c->enabled = 1;
        c->combine = combine_notes_concatenate;
-       c->refs = xcalloc(1, sizeof(struct string_list));
+       CALLOC_ARRAY(c->refs, 1);
        c->refs->strdup_strings = 1;
        c->refs_from_env = 0;
        c->mode_from_env = 0;
diff --git a/notes.c b/notes.c
index d5ac081e76df9cd03edd273177a15e42aa25d407..a19e4ad79434336eea35b614342534a19a56042e 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -452,7 +452,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
                        goto handle_non_note;
                }
 
-               l = xcalloc(1, sizeof(*l));
+               CALLOC_ARRAY(l, 1);
                oidcpy(&l->key_oid, &object_oid);
                oidcpy(&l->val_oid, &entry.oid);
                if (note_tree_insert(t, node, n, l, type,
index 5bcfde84718868ac6ae35cddfc102d4a13f0c502..624af408cdcd2aec95b1f54882a0c8027a60c723 100644 (file)
@@ -546,7 +546,7 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,
                return -1;
        }
 
-       ent = xcalloc(1, sizeof(*ent));
+       CALLOC_ARRAY(ent, 1);
        ent->path = xstrdup(pathbuf.buf);
 
        /* add the alternate entry */
index 98017bed8efb7eaf45d30a20c07a0870c4acceaa..78343781ae77d6f60be8d7477422f883e2966cca 100644 (file)
--- a/object.c
+++ b/object.c
@@ -127,7 +127,7 @@ static void grow_object_hash(struct repository *r)
        int new_hash_size = r->parsed_objects->obj_hash_size < 32 ? 32 : 2 * r->parsed_objects->obj_hash_size;
        struct object **new_hash;
 
-       new_hash = xcalloc(new_hash_size, sizeof(struct object *));
+       CALLOC_ARRAY(new_hash, new_hash_size);
        for (i = 0; i < r->parsed_objects->obj_hash_size; i++) {
                struct object *obj = r->parsed_objects->obj_hash[i];
 
@@ -478,7 +478,7 @@ struct parsed_object_pool *parsed_object_pool_new(void)
        o->object_state = allocate_alloc_state();
 
        o->is_shallow = -1;
-       o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
+       CALLOC_ARRAY(o->shallow_stat, 1);
 
        o->buffer_slab = allocate_commit_buffer_slab();
 
index 1f69b5fa85354b76169f93139a29e7d98846795f..1ebe0c81628a35932c3d05ccb1306834442568a0 100644 (file)
@@ -978,7 +978,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
 
        /* try to open a bitmapped pack, but don't parse it yet
         * because we may not need to use it */
-       bitmap_git = xcalloc(1, sizeof(*bitmap_git));
+       CALLOC_ARRAY(bitmap_git, 1);
        if (open_pack_bitmap(revs->repo, bitmap_git) < 0)
                goto cleanup;
 
@@ -1388,7 +1388,7 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
        uint32_t *reposition;
 
        num_objects = bitmap_git->pack->num_objects;
-       reposition = xcalloc(num_objects, sizeof(uint32_t));
+       CALLOC_ARRAY(reposition, num_objects);
 
        for (i = 0; i < num_objects; ++i) {
                struct object_id oid;
index f2a433885ac80ec9cbadfd3e5e7553655237c924..fe2a4eace9910b487aae56447b7fc6bd93fe1392 100644 (file)
@@ -49,7 +49,7 @@ static void rehash_objects(struct packing_data *pdata)
                pdata->index_size = 1024;
 
        free(pdata->index);
-       pdata->index = xcalloc(pdata->index_size, sizeof(*pdata->index));
+       CALLOC_ARRAY(pdata->index, pdata->index_size);
 
        entry = pdata->objects;
 
index 1fec12ac5f4c74448d5bf58699d9a05f654ef3b6..ea29f4ba77356049ea80bcf9b5276d8781910d7c 100644 (file)
@@ -638,7 +638,7 @@ unsigned char *use_pack(struct packed_git *p,
                        if (p->pack_fd == -1 && open_packed_git(p))
                                die("packfile %s cannot be accessed", p->pack_name);
 
-                       win = xcalloc(1, sizeof(*win));
+                       CALLOC_ARRAY(win, 1);
                        win->offset = (offset / window_align) * window_align;
                        len = p->pack_size - win->offset;
                        if (len > packed_git_window_size)
index 3f404e4b0b4cc24d02ae9cbf3c8498c37f673094..8bf425555de252f12935b4fae68f375f3a815987 100644 (file)
@@ -124,7 +124,7 @@ struct patch_id *add_commit_patch_id(struct commit *commit,
        if (!patch_id_defined(commit))
                return NULL;
 
-       key = xcalloc(1, sizeof(*key));
+       CALLOC_ARRAY(key, 1);
        if (init_patch_id_entry(key, commit, ids)) {
                free(key);
                return NULL;
index 7a229d8d22f2f67a8e267fda302b53b35a13a3d4..18b3be362ae988ddac9a5be78a7f5de8414767aa 100644 (file)
@@ -154,7 +154,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va
        string_list_remove_empty_items(&list, 0);
 
        item->attr_check = attr_check_alloc();
-       item->attr_match = xcalloc(list.nr, sizeof(struct attr_match));
+       CALLOC_ARRAY(item->attr_match, list.nr);
 
        for_each_string_list_item(si, &list) {
                size_t attr_len;
@@ -561,7 +561,7 @@ void parse_pathspec(struct pathspec *pathspec,
                if (!(flags & PATHSPEC_PREFER_CWD))
                        BUG("PATHSPEC_PREFER_CWD requires arguments");
 
-               pathspec->items = item = xcalloc(1, sizeof(*item));
+               pathspec->items = CALLOC_ARRAY(item, 1);
                item->match = xstrdup(prefix);
                item->original = xstrdup(prefix);
                item->nowildcard_len = item->len = strlen(prefix);
index c5f5ecc40d3fa24c6015420a1a8e8cfc3f446a07..d5efd00e219163068b4312d68e54ce36d3610922 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -678,7 +678,7 @@ static int mailmap_name(const char **email, size_t *email_len,
 {
        static struct string_list *mail_map;
        if (!mail_map) {
-               mail_map = xcalloc(1, sizeof(*mail_map));
+               CALLOC_ARRAY(mail_map, 1);
                read_mailmap(mail_map);
        }
        return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
index 31014e6fca0512d16b0fbcc35c7fbfd43426e5c8..680c6a8bf93b514a7b82510c475984ca32067eb7 100644 (file)
@@ -196,7 +196,7 @@ void display_throughput(struct progress *progress, uint64_t total)
        now_ns = progress_getnanotime(progress);
 
        if (!tp) {
-               progress->throughput = tp = xcalloc(1, sizeof(*tp));
+               progress->throughput = CALLOC_ARRAY(tp, 1);
                tp->prev_total = tp->curr_total = total;
                tp->prev_ns = now_ns;
                strbuf_init(&tp->display, 0);
index 3c572b1c811e0b8912a11e3f193eb79f131ee763..da3f2ca2615e0896878edf00f36577c85d2dc429 100644 (file)
@@ -208,7 +208,7 @@ static int remove_fetched_oids(struct repository *repo,
 
        if (remaining_nr) {
                int j = 0;
-               new_oids = xcalloc(remaining_nr, sizeof(*new_oids));
+               CALLOC_ARRAY(new_oids, remaining_nr);
                for (i = 0; i < oid_nr; i++)
                        if (remaining[i])
                                oidcpy(&new_oids[j++], &old_oids[i]);
index a3cc7c94a3d5c881a0eb9037a06c1a7cf8803bbd..116fb0735c6f4908b126d8471c9a8a52be9ccc21 100644 (file)
@@ -96,7 +96,7 @@ static int read_patches(const char *range, struct string_list *list,
                                string_list_append(list, buf.buf)->util = util;
                                strbuf_reset(&buf);
                        }
-                       util = xcalloc(sizeof(*util), 1);
+                       CALLOC_ARRAY(util, 1);
                        if (get_oid(p, &util->oid)) {
                                error(_("could not parse commit '%s'"), p);
                                free(util);
index 1e9a50c6c734374aa59ff97b9f9e5432918bf1f8..c8d12eaa3c36d5339186a62a51c763ff82786243 100644 (file)
@@ -2097,7 +2097,7 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con
        /* ensure we have no more threads than we have blocks to process */
        if (nr_threads > ieot->nr)
                nr_threads = ieot->nr;
-       data = xcalloc(nr_threads, sizeof(*data));
+       CALLOC_ARRAY(data, nr_threads);
 
        offset = ieot_start = 0;
        ieot_blocks = DIV_ROUND_UP(ieot->nr, nr_threads);
@@ -2199,7 +2199,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
-       istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));
+       CALLOC_ARRAY(istate->cache, istate->cache_alloc);
        istate->initialized = 1;
 
        p.istate = istate;
@@ -2326,7 +2326,7 @@ int read_index_from(struct index_state *istate, const char *path,
        if (split_index->base)
                discard_index(split_index->base);
        else
-               split_index->base = xcalloc(1, sizeof(*split_index->base));
+               CALLOC_ARRAY(split_index->base, 1);
 
        base_oid_hex = oid_to_hex(&split_index->base_oid);
        base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
@@ -3427,7 +3427,7 @@ void stat_validity_update(struct stat_validity *sv, int fd)
                stat_validity_clear(sv);
        else {
                if (!sv->sd)
-                       sv->sd = xcalloc(1, sizeof(struct stat_data));
+                       CALLOC_ARRAY(sv->sd, 1);
                fill_stat_data(sv->sd, &st);
        }
 }
index e84efb53dbf5b854cbb9d492d1d456f7e1ef3d17..643e69bda658070a54e71c35008cd51e5d690300 100644 (file)
@@ -1676,7 +1676,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
        int i;
        struct object_info empty = OBJECT_INFO_INIT;
 
-       ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
+       CALLOC_ARRAY(ref->value, used_atom_cnt);
 
        if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
                ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
@@ -2185,7 +2185,7 @@ static void reach_filter(struct ref_array *array,
        if (!check_reachable)
                return;
 
-       to_clear = xcalloc(sizeof(struct commit *), array->nr);
+       CALLOC_ARRAY(to_clear, array->nr);
 
        repo_init_revisions(the_repository, &revs, NULL);
 
@@ -2490,7 +2490,7 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
 {
        struct ref_sorting *s;
 
-       s = xcalloc(1, sizeof(*s));
+       CALLOC_ARRAY(s, 1);
        s->next = *sorting_tail;
        *sorting_tail = s;
 
index 3a25b27d8f8dbd49b4c33c81cb6af3c92f59759d..e9cd3283694decbc6ea8e72c5681766129df793d 100644 (file)
@@ -112,7 +112,7 @@ struct reflog_walk_info {
 
 void init_reflog_walk(struct reflog_walk_info **info)
 {
-       *info = xcalloc(1, sizeof(struct reflog_walk_info));
+       CALLOC_ARRAY(*info, 1);
        (*info)->complete_reflogs.strdup_strings = 1;
 }
 
@@ -181,7 +181,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
        }
        free(branch);
 
-       commit_reflog = xcalloc(1, sizeof(struct commit_reflog));
+       CALLOC_ARRAY(commit_reflog, 1);
        if (recno < 0) {
                commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
                if (commit_reflog->recno < 0) {
diff --git a/refs.c b/refs.c
index a665ed5e10acb65f821cfed9e6586c277bdceb48..261fd82beb98fdfcfc641fa7605d37b86aac2184 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1007,7 +1007,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
        struct ref_transaction *tr;
        assert(err);
 
-       tr = xcalloc(1, sizeof(struct ref_transaction));
+       CALLOC_ARRAY(tr, 1);
        tr->ref_store = refs;
        return tr;
 }
@@ -1306,7 +1306,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
                while (len && ref[len - 1] == '/')
                        ref[--len] = '\0';
                if (!hide_refs) {
-                       hide_refs = xcalloc(1, sizeof(*hide_refs));
+                       CALLOC_ARRAY(hide_refs, 1);
                        hide_refs->strdup_strings = 1;
                }
                string_list_append(hide_refs, ref);
index 4fdc68810b3c1563d8e7301a67d9ff1396be3bbf..119972ee16f89f629e96b552e520f0b8190e54a7 100644 (file)
@@ -549,7 +549,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
 
        /* First lock the file so it can't change out from under us. */
 
-       *lock_p = lock = xcalloc(1, sizeof(*lock));
+       *lock_p = CALLOC_ARRAY(lock, 1);
 
        lock->ref_name = xstrdup(refname);
        files_ref_path(refs, &ref_file, refname);
@@ -843,7 +843,7 @@ static struct ref_iterator *files_ref_iterator_begin(
 
        overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);
 
-       iter = xcalloc(1, sizeof(*iter));
+       CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
        base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
                               overlay_iter->ordered);
@@ -930,7 +930,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
        files_assert_main_repository(refs, "lock_ref_oid_basic");
        assert(err);
 
-       lock = xcalloc(1, sizeof(struct ref_lock));
+       CALLOC_ARRAY(lock, 1);
 
        if (mustexist)
                resolve_flags |= RESOLVE_REF_READING;
@@ -2152,7 +2152,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
                return empty_ref_iterator_begin();
        }
 
-       iter = xcalloc(1, sizeof(*iter));
+       CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
 
        base_ref_iterator_init(ref_iterator, &files_reflog_iterator_vtable, 0);
@@ -2597,7 +2597,7 @@ static int files_transaction_prepare(struct ref_store *ref_store,
        if (!transaction->nr)
                goto cleanup;
 
-       backend_data = xcalloc(1, sizeof(*backend_data));
+       CALLOC_ARRAY(backend_data, 1);
        transaction->backend_data = backend_data;
 
        /*
index 629e00a122a7a867ae3350ce35469c2ceb1259a1..a89d132d4fe7796f4ba8edbadbdfc5cdd8cd5978 100644 (file)
@@ -393,7 +393,7 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
        if (!*prefix && !trim)
                return iter0; /* optimization: no need to wrap iterator */
 
-       iter = xcalloc(1, sizeof(*iter));
+       CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
 
        base_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable, iter0->ordered);
index b912f2505fee298225d3daa5719cbe6bdeba2365..dfecdbc1db6074aeafb995440fa22901b4997331 100644 (file)
@@ -941,7 +941,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
        if (start == snapshot->eof)
                return empty_ref_iterator_begin();
 
-       iter = xcalloc(1, sizeof(*iter));
+       CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
        base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1);
 
@@ -1424,7 +1424,7 @@ static int packed_transaction_prepare(struct ref_store *ref_store,
         * do so itself.
         */
 
-       data = xcalloc(1, sizeof(*data));
+       CALLOC_ARRAY(data, 1);
        string_list_init(&data->updates, 0);
 
        transaction->backend_data = data;
index b7052f72e2f4e61ea9f2bba5efee262e6db8fd4a..46f1e54284339dfce975f9820151c020327b85b7 100644 (file)
@@ -530,7 +530,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
        if (prime_dir)
                prime_ref_dir(dir, prefix);
 
-       iter = xcalloc(1, sizeof(*iter));
+       CALLOC_ARRAY(iter, 1);
        ref_iterator = &iter->base;
        base_ref_iterator_init(ref_iterator, &cache_ref_iterator_vtable, 1);
        ALLOC_GROW(iter->levels, 10, iter->levels_alloc);
index c3f85c17ca7c79c7d9d9fd12defc36a22089b89c..6d1e8d02dfe7863cef5bbbe27b555d30fda8c5b7 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -151,7 +151,7 @@ static struct remote *make_remote(const char *name, int len)
        if (e)
                return container_of(e, struct remote, ent);
 
-       ret = xcalloc(1, sizeof(struct remote));
+       CALLOC_ARRAY(ret, 1);
        ret->prune = -1;  /* unspecified */
        ret->prune_tags = -1;  /* unspecified */
        ret->name = xstrndup(name, len);
@@ -186,7 +186,7 @@ static struct branch *make_branch(const char *name, size_t len)
        }
 
        ALLOC_GROW(branches, branches_nr + 1, branches_alloc);
-       ret = xcalloc(1, sizeof(struct branch));
+       CALLOC_ARRAY(ret, 1);
        branches[branches_nr++] = ret;
        ret->name = xstrndup(name, len);
        ret->refname = xstrfmt("refs/heads/%s", ret->name);
@@ -207,7 +207,7 @@ static struct rewrite *make_rewrite(struct rewrites *r,
        }
 
        ALLOC_GROW(r->rewrite, r->rewrite_nr + 1, r->rewrite_alloc);
-       ret = xcalloc(1, sizeof(struct rewrite));
+       CALLOC_ARRAY(ret, 1);
        r->rewrite[r->rewrite_nr++] = ret;
        ret->base = xstrndup(base, len);
        ret->baselen = len;
@@ -1664,7 +1664,7 @@ static void set_merge(struct branch *ret)
 
        remote = remote_get(ret->remote_name);
 
-       ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge));
+       CALLOC_ARRAY(ret->merge, ret->merge_nr);
        for (i = 0; i < ret->merge_nr; i++) {
                ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
                ret->merge[i]->src = xstrdup(ret->merge_name[i]);
index c98298acd017b551894f838e2000b253b271202e..87b355e7a6597b8b1573b1ac34c3d6c102f84238 100644 (file)
@@ -72,7 +72,7 @@ void repo_set_gitdir(struct repository *repo,
        repo_set_commondir(repo, o->commondir);
 
        if (!repo->objects->odb) {
-               repo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb));
+               CALLOC_ARRAY(repo->objects->odb, 1);
                repo->objects->odb_tail = &repo->objects->odb->next;
        }
        expand_base_dir(&repo->objects->odb->path, o->object_dir,
@@ -262,7 +262,7 @@ void repo_clear(struct repository *repo)
 int repo_read_index(struct repository *repo)
 {
        if (!repo->index)
-               repo->index = xcalloc(1, sizeof(*repo->index));
+               CALLOC_ARRAY(repo->index, 1);
 
        /* Complete the double-reference */
        if (!repo->index->repo)
index 236320f179cbf60a312f882ee57e1f843398e907..bbd2e57fe418dd55480cb7447aafc858625fddf0 100644 (file)
@@ -15,7 +15,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
                return;
 
        if (!istate->resolve_undo) {
-               resolve_undo = xcalloc(1, sizeof(*resolve_undo));
+               CALLOC_ARRAY(resolve_undo, 1);
                resolve_undo->strdup_strings = 1;
                istate->resolve_undo = resolve_undo;
        }
@@ -57,7 +57,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
        int i;
        const unsigned rawsz = the_hash_algo->rawsz;
 
-       resolve_undo = xcalloc(1, sizeof(*resolve_undo));
+       CALLOC_ARRAY(resolve_undo, 1);
        resolve_undo->strdup_strings = 1;
 
        while (size) {
index b78733f5089b0dcef8eed71c44243a3b9a6f86db..99c859f7971b336df97505c8bf1d9eafe23bf02e 100644 (file)
@@ -154,7 +154,7 @@ static void paths_and_oids_insert(struct hashmap *map,
 
        entry = hashmap_get_entry(map, &key, ent, NULL);
        if (!entry) {
-               entry = xcalloc(1, sizeof(struct path_and_oids_entry));
+               CALLOC_ARRAY(entry, 1);
                hashmap_entry_init(&entry->ent, hash);
                entry->path = xstrdup(key.path);
                oidset_init(&entry->trees, 16);
@@ -1555,7 +1555,7 @@ void clear_ref_exclusion(struct string_list **ref_excludes_p)
 void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)
 {
        if (!*ref_excludes_p) {
-               *ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p));
+               CALLOC_ARRAY(*ref_excludes_p, 1);
                (*ref_excludes_p)->strdup_strings = 1;
        }
        string_list_append(*ref_excludes_p, exclude);
@@ -2929,7 +2929,7 @@ static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs,
 
        st = lookup_decoration(&revs->merge_simplification, &commit->object);
        if (!st) {
-               st = xcalloc(1, sizeof(*st));
+               CALLOC_ARRAY(st, 1);
                add_decoration(&revs->merge_simplification, &commit->object, st);
        }
        return st;
index 4e34623e2e29ebdbf18f2204c6e52752d4db7259..be6bc128cd9df2f61211cb7b8f9552b2d745cc0a 100644 (file)
@@ -1638,8 +1638,8 @@ static void pp_init(struct parallel_processes *pp,
        pp->nr_processes = 0;
        pp->output_owner = 0;
        pp->shutdown = 0;
-       pp->children = xcalloc(n, sizeof(*pp->children));
-       pp->pfd = xcalloc(n, sizeof(*pp->pfd));
+       CALLOC_ARRAY(pp->children, n);
+       CALLOC_ARRAY(pp->pfd, n);
        strbuf_init(&pp->buffered_output, 0);
 
        for (i = 0; i < n; i++) {
index 9045f8a082bcd62c8ee116dc235561574ed35326..5f215b13c7dc1a8a020094236625554db94591b2 100644 (file)
@@ -188,13 +188,13 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
                        }
                        if (new_report) {
                                if (!hint->report) {
-                                       hint->report = xcalloc(1, sizeof(struct ref_push_report));
+                                       CALLOC_ARRAY(hint->report, 1);
                                        report = hint->report;
                                } else {
                                        report = hint->report;
                                        while (report->next)
                                                report = report->next;
-                                       report->next = xcalloc(1, sizeof(struct ref_push_report));
+                                       CALLOC_ARRAY(report->next, 1);
                                        report = report->next;
                                }
                                new_report = 0;
index d2332d3e1787126f50f3e5f01652c00911c8eda9..848204d3dc3f50efe9f2813d879173bc117eb606 100644 (file)
@@ -5171,7 +5171,7 @@ void todo_list_add_exec_commands(struct todo_list *todo_list,
        int i, insert, nr = 0, alloc = 0;
        struct todo_item *items = NULL, *base_items = NULL;
 
-       base_items = xcalloc(commands->nr, sizeof(struct todo_item));
+       CALLOC_ARRAY(base_items, commands->nr);
        for (i = 0; i < commands->nr; i++) {
                size_t command_len = strlen(commands->items[i].string);
 
index bae2cdfd5127e42ca66622270326d8094fe13f40..de0aa4498c6131da80fb9ef8afb061fc1b9aff7e 100644 (file)
@@ -296,7 +296,7 @@ static void init_pack_info(const char *infofile, int force)
 
                i = num_pack++;
                ALLOC_GROW(info, num_pack, alloc);
-               info[i] = xcalloc(1, sizeof(struct pack_info));
+               CALLOC_ARRAY(info[i], 1);
                info[i]->p = p;
                info[i]->old_num = -1;
        }
index c0e8ad670d0a17a28fd049b6814d8e77c7654dc2..94937d21a39da8e0e3de9413019fdeae3db06a20 100644 (file)
@@ -5,7 +5,7 @@
 struct split_index *init_split_index(struct index_state *istate)
 {
        if (!istate->split_index) {
-               istate->split_index = xcalloc(1, sizeof(*istate->split_index));
+               CALLOC_ARRAY(istate->split_index, 1);
                istate->split_index->refcount = 1;
        }
        return istate->split_index;
@@ -87,7 +87,7 @@ void move_cache_to_base_index(struct index_state *istate)
                mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
        }
 
-       si->base = xcalloc(1, sizeof(*si->base));
+       CALLOC_ARRAY(si->base, 1);
        si->base->version = istate->version;
        /* zero timestamp disables racy test in ce_write_index() */
        si->base->timestamp = istate->timestamp;
index 249ed618ed8e26c966c6d9815db0645c994ae4f5..53081650e0c75a5b576de5383f10df0c38966897 100644 (file)
--- a/trailer.c
+++ b/trailer.c
@@ -445,7 +445,7 @@ static struct arg_item *get_conf_item(const char *name)
        }
 
        /* Item does not already exists, create it */
-       item = xcalloc(sizeof(*item), 1);
+       CALLOC_ARRAY(item, 1);
        duplicate_conf(&item->conf, &default_conf_info);
        item->conf.name = xstrdup(name);
 
index 49b7fb4dcb9a3012a9bdc60bc6fa581a47875e07..4cd76366fa94b8e3bb8314685fe4ff4b4380127c 100644 (file)
@@ -745,13 +745,13 @@ static int push_update_ref_status(struct strbuf *buf,
                        die(_("'option' without a matching 'ok/error' directive"));
                if (state->new_report) {
                        if (!state->hint->report) {
-                               state->hint->report = xcalloc(1, sizeof(struct ref_push_report));
+                               CALLOC_ARRAY(state->hint->report, 1);
                                state->report = state->hint->report;
                        } else {
                                state->report = state->hint->report;
                                while (state->report->next)
                                        state->report = state->report->next;
-                               state->report->next = xcalloc(1, sizeof(struct ref_push_report));
+                               CALLOC_ARRAY(state->report->next, 1);
                                state->report = state->report->next;
                        }
                        state->new_report = 0;
index b13fab5dc3b1b90933b77f15fe87ca422cc70784..1c4ab676d1b148835431106d99766545c31da721 100644 (file)
@@ -871,7 +871,7 @@ void transport_take_over(struct transport *transport,
                BUG("taking over transport requires non-NULL "
                    "smart_options field.");
 
-       data = xcalloc(1, sizeof(*data));
+       CALLOC_ARRAY(data, 1);
        data->options = *transport->smart_options;
        data->conn = child;
        data->fd[0] = data->conn->out;
index e00858540ea45965f1570739caa4713a66a36105..f35ac40a84a5133d86aa2b92f10fe69ec13e2241 100644 (file)
@@ -53,7 +53,7 @@ static struct worktree *get_main_worktree(void)
        strbuf_add_real_path(&worktree_path, get_git_common_dir());
        strbuf_strip_suffix(&worktree_path, "/.git");
 
-       worktree = xcalloc(1, sizeof(*worktree));
+       CALLOC_ARRAY(worktree, 1);
        worktree->path = strbuf_detach(&worktree_path, NULL);
        /*
         * NEEDSWORK: If this function is called from a secondary worktree and
@@ -84,7 +84,7 @@ static struct worktree *get_linked_worktree(const char *id)
        strbuf_rtrim(&worktree_path);
        strbuf_strip_suffix(&worktree_path, "/.git");
 
-       worktree = xcalloc(1, sizeof(*worktree));
+       CALLOC_ARRAY(worktree, 1);
        worktree->path = strbuf_detach(&worktree_path, NULL);
        worktree->id = xstrdup(id);
        add_head_info(worktree);
index 0c8287a023e4d834f7b0a5a437f1b89c18f7c05c..1aed68c43c264c360de8282485c6c93a5dc43d08 100644 (file)
@@ -456,7 +456,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
                it = string_list_insert(&s->change, p->two->path);
                d = it->util;
                if (!d) {
-                       d = xcalloc(1, sizeof(*d));
+                       CALLOC_ARRAY(d, 1);
                        it->util = d;
                }
                if (!d->worktree_status)
@@ -540,7 +540,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
                it = string_list_insert(&s->change, p->two->path);
                d = it->util;
                if (!d) {
-                       d = xcalloc(1, sizeof(*d));
+                       CALLOC_ARRAY(d, 1);
                        it->util = d;
                }
                if (!d->index_status)
@@ -671,7 +671,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
                it = string_list_insert(&s->change, ce->name);
                d = it->util;
                if (!d) {
-                       d = xcalloc(1, sizeof(*d));
+                       CALLOC_ARRAY(d, 1);
                        it->util = d;
                }
                if (ce_stage(ce)) {