use CALLOC_ARRAY
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>
René Scharfe committed
Mar 13, 2021 at 17:17 UTC
ca56dadb4b65ccaeab809d80db80a312dc00941a
88 files changed
+190
-188
add-interactive.c
+1
-1
@@ -476,7 +476,7 @@ static void collect_changes_cb(struct diff_queue_struct *q,
476
477
add_file_item(s->files, name);
478
479
- entry = xcalloc(sizeof(*entry), 1);
479
+ CALLOC_ARRAY(entry, 1);
480
hashmap_entry_init(&entry->ent, hash);
481
entry->name = s->files->items[s->files->nr - 1].string;
482
entry->item = s->files->items[s->files->nr - 1].util;
apply.c
+3
-3
@@ -1781,7 +1781,7 @@ static int parse_single_patch(struct apply_state *state,
1781
struct fragment *fragment;
1782
int len;
1783
1784
- fragment = xcalloc(1, sizeof(*fragment));
1784
+ CALLOC_ARRAY(fragment, 1);
1785
fragment->linenr = state->linenr;
1786
len = parse_fragment(state, line, size, patch, fragment);
1787
if (len <= 0) {
@@ -1959,7 +1959,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,
1959
size -= llen;
1960
}
1961
1962
- frag = xcalloc(1, sizeof(*frag));
1962
+ CALLOC_ARRAY(frag, 1);
1963
frag->patch = inflate_it(data, hunk_size, origlen);
1964
frag->free_patch = 1;
1965
if (!frag->patch)
@@ -4681,7 +4681,7 @@ static int apply_patch(struct apply_state *state,
4681
struct patch *patch;
4682
int nr;
4683
4684
- patch = xcalloc(1, sizeof(*patch));
4684
+ CALLOC_ARRAY(patch, 1);
4685
patch->inaccurate_eof = !!(options & APPLY_OPT_INACCURATE_EOF);
4686
patch->recount = !!(options & APPLY_OPT_RECOUNT);
4687
nr = parse_chunk(state, buf.buf + offset, buf.len - offset, patch);
archive-tar.c
+1
-1
@@ -371,7 +371,7 @@ static int tar_filter_config(const char *var, const char *value, void *data)
371
372
ar = find_tar_filter(name, namelen);
373
if (!ar) {
374
- ar = xcalloc(1, sizeof(*ar));
374
+ CALLOC_ARRAY(ar, 1);
375
ar->name = xmemdupz(name, namelen);
376
ar->write_archive = write_tar_filter_archive;
377
ar->flags = ARCHIVER_WANT_COMPRESSION_LEVELS |
attr.c
+6
-6
@@ -569,7 +569,7 @@ struct attr_check *attr_check_initl(const char *one, ...)
569
check = attr_check_alloc();
570
check->nr = cnt;
571
check->alloc = cnt;
572
- check->items = xcalloc(cnt, sizeof(struct attr_check_item));
572
+ CALLOC_ARRAY(check->items, cnt);
573
574
check->items[0].attr = git_attr(one);
575
va_start(params, one);
@@ -670,7 +670,7 @@ static struct attr_stack *read_attr_from_array(const char **list)
670
const char *line;
671
int lineno = 0;
672
673
- res = xcalloc(1, sizeof(*res));
673
+ CALLOC_ARRAY(res, 1);
674
while ((line = *(list++)) != NULL)
675
handle_attr_line(res, line, "[builtin]", ++lineno, 1);
676
return res;
@@ -707,7 +707,7 @@ static struct attr_stack *read_attr_from_file(const char *path, int macro_ok)
707
708
if (!fp)
709
return NULL;
710
- res = xcalloc(1, sizeof(*res));
710
+ CALLOC_ARRAY(res, 1);
711
while (fgets(buf, sizeof(buf), fp)) {
712
char *bufp = buf;
713
if (!lineno)
@@ -733,7 +733,7 @@ static struct attr_stack *read_attr_from_index(const struct index_state *istate,
733
if (!buf)
734
return NULL;
735
736
- res = xcalloc(1, sizeof(*res));
736
+ CALLOC_ARRAY(res, 1);
737
for (sp = buf; *sp; ) {
738
char *ep;
739
int more;
@@ -774,7 +774,7 @@ static struct attr_stack *read_attr(const struct index_state *istate,
774
}
775
776
if (!res)
777
- res = xcalloc(1, sizeof(*res));
777
+ CALLOC_ARRAY(res, 1);
778
return res;
779
}
780
@@ -874,7 +874,7 @@ static void bootstrap_attr_stack(const struct index_state *istate,
874
else
875
e = NULL;
876
if (!e)
877
- e = xcalloc(1, sizeof(struct attr_stack));
877
+ CALLOC_ARRAY(e, 1);
878
push_stack(stack, e, NULL, 0);
879
}
880
bisect.c
+1
-1
@@ -423,7 +423,7 @@ void find_bisection(struct commit_list **commit_list, int *reaches,
423
show_list("bisection 2 sorted", 0, nr, list);
424
425
*all = nr;
426
- weights = xcalloc(on_list, sizeof(*weights));
426
+ CALLOC_ARRAY(weights, on_list);
427
428
/* Do the real work of finding bisection commit. */
429
best = do_find_bisection(list, nr, weights, bisect_flags);
blame.c
+8
-9
@@ -951,13 +951,13 @@ static int *fuzzy_find_matching_lines(struct blame_origin *parent,
951
max_search_distance_b = ((2 * max_search_distance_a + 1) * length_b
952
- 1) / length_a;
953
954
- result = xcalloc(sizeof(int), length_b);
955
- second_best_result = xcalloc(sizeof(int), length_b);
956
- certainties = xcalloc(sizeof(int), length_b);
954
+ CALLOC_ARRAY(result, length_b);
955
+ CALLOC_ARRAY(second_best_result, length_b);
956
+ CALLOC_ARRAY(certainties, length_b);
957
958
/* See get_similarity() for details of similarities. */
959
similarity_count = length_b * (max_search_distance_a * 2 + 1);
960
- similarities = xcalloc(sizeof(int), similarity_count);
960
+ CALLOC_ARRAY(similarities, similarity_count);
961
962
for (i = 0; i < length_b; ++i) {
963
result[i] = -1;
@@ -995,7 +995,7 @@ static void fill_origin_fingerprints(struct blame_origin *o)
995
return;
996
o->num_lines = find_line_starts(&line_starts, o->file.ptr,
997
o->file.size);
998
- o->fingerprints = xcalloc(sizeof(struct fingerprint), o->num_lines);
998
+ CALLOC_ARRAY(o->fingerprints, o->num_lines);
999
get_line_fingerprints(o->fingerprints, o->file.ptr, line_starts,
1000
0, o->num_lines);
1001
free(line_starts);
@@ -1853,8 +1853,7 @@ static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq,
1853
diffp = NULL;
1854
1855
if (ignore_diffs && same - tlno > 0) {
1856
- line_blames = xcalloc(sizeof(struct blame_line_tracker),
1857
- same - tlno);
1856
+ CALLOC_ARRAY(line_blames, same - tlno);
1857
guess_line_blames(parent, target, tlno, offset, same,
1858
parent_len, line_blames);
1859
}
@@ -2216,7 +2215,7 @@ static struct blame_list *setup_blame_list(struct blame_entry *unblamed,
2215
for (e = unblamed, num_ents = 0; e; e = e->next)
2216
num_ents++;
2217
if (num_ents) {
2219
- blame_list = xcalloc(num_ents, sizeof(struct blame_list));
2218
+ CALLOC_ARRAY(blame_list, num_ents);
2219
for (e = unblamed, i = 0; e; e = e->next)
2220
blame_list[i++].ent = e;
2221
}
@@ -2428,7 +2427,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
2427
else if (num_sg < ARRAY_SIZE(sg_buf))
2428
memset(sg_buf, 0, sizeof(sg_buf));
2429
else
2431
- sg_origin = xcalloc(num_sg, sizeof(*sg_origin));
2430
+ CALLOC_ARRAY(sg_origin, num_sg);
2431
2432
/*
2433
* The first pass looks for unrenamed path to optimize for
bloom.c
+1
-1
@@ -277,7 +277,7 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
277
*computed |= BLOOM_TRUNC_EMPTY;
278
filter->len = 1;
279
}
280
- filter->data = xcalloc(filter->len, sizeof(unsigned char));
280
+ CALLOC_ARRAY(filter->data, filter->len);
281
282
hashmap_for_each_entry(&pathmap, &iter, e, entry) {
283
struct bloom_key key;
builtin/clean.c
+1
-1
@@ -623,7 +623,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
623
nr += chosen[i];
624
}
625
626
- result = xcalloc(st_add(nr, 1), sizeof(int));
626
+ CALLOC_ARRAY(result, st_add(nr, 1));
627
for (i = 0; i < stuff->nr && j < nr; i++) {
628
if (chosen[i])
629
result[j++] = i;
builtin/fast-import.c
+4
-4
@@ -3322,7 +3322,7 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list)
3322
die(_("Expected format name:filename for submodule rewrite option"));
3323
*f = '\0';
3324
f++;
3325
- ms = xcalloc(1, sizeof(*ms));
3325
+ CALLOC_ARRAY(ms, 1);
3326
3327
fp = fopen(f, "r");
3328
if (!fp)
@@ -3519,9 +3519,9 @@ int cmd_fast_import(int argc, const char **argv, const char *prefix)
3519
3520
alloc_objects(object_entry_alloc);
3521
strbuf_init(&command_buf, 0);
3522
- atom_table = xcalloc(atom_table_sz, sizeof(struct atom_str*));
3523
- branch_table = xcalloc(branch_table_sz, sizeof(struct branch*));
3524
- avail_tree_table = xcalloc(avail_tree_table_sz, sizeof(struct avail_tree_content*));
3522
+ CALLOC_ARRAY(atom_table, atom_table_sz);
3523
+ CALLOC_ARRAY(branch_table, branch_table_sz);
3524
+ CALLOC_ARRAY(avail_tree_table, avail_tree_table_sz);
3525
marks = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set));
3526
3527
hashmap_init(&object_table, object_entry_hashcmp, NULL, 0);
builtin/grep.c
+1
-1
@@ -211,7 +211,7 @@ static void start_threads(struct grep_opt *opt)
211
strbuf_init(&todo[i].out, 0);
212
}
213
214
- threads = xcalloc(num_threads, sizeof(*threads));
214
+ CALLOC_ARRAY(threads, num_threads);
215
for (i = 0; i < num_threads; i++) {
216
int err;
217
struct grep_opt *o = grep_opt_dup(opt);
builtin/index-pack.c
+5
-5
@@ -185,7 +185,7 @@ static void init_thread(void)
185
if (show_stat)
186
pthread_mutex_init(&deepest_delta_mutex, NULL);
187
pthread_key_create(&key, NULL);
188
- thread_data = xcalloc(nr_threads, sizeof(*thread_data));
188
+ CALLOC_ARRAY(thread_data, nr_threads);
189
for (i = 0; i < nr_threads; i++) {
190
thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
191
if (thread_data[i].pack_fd == -1)
@@ -1674,7 +1674,7 @@ static void show_pack_info(int stat_only)
1674
unsigned long *chain_histogram = NULL;
1675
1676
if (deepest_delta)
1677
- chain_histogram = xcalloc(deepest_delta, sizeof(unsigned long));
1677
+ CALLOC_ARRAY(chain_histogram, deepest_delta);
1678
1679
for (i = 0; i < nr_objects; i++) {
1680
struct object_entry *obj = &objects[i];
@@ -1912,10 +1912,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
1912
1913
curr_pack = open_pack_file(pack_name);
1914
parse_pack_header();
1915
- objects = xcalloc(st_add(nr_objects, 1), sizeof(struct object_entry));
1915
+ CALLOC_ARRAY(objects, st_add(nr_objects, 1));
1916
if (show_stat)
1917
- obj_stat = xcalloc(st_add(nr_objects, 1), sizeof(struct object_stat));
1918
- ofs_deltas = xcalloc(nr_objects, sizeof(struct ofs_delta_entry));
1917
+ CALLOC_ARRAY(obj_stat, st_add(nr_objects, 1));
1918
+ CALLOC_ARRAY(ofs_deltas, nr_objects);
1919
parse_pack_objects(pack_hash);
1920
if (report_end_of_input)
1921
write_in_full(2, "\0", 1);
builtin/ls-remote.c
+1
-1
@@ -88,7 +88,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
88
89
if (argc > 1) {
90
int i;
91
- pattern = xcalloc(argc, sizeof(const char *));
91
+ CALLOC_ARRAY(pattern, argc);
92
for (i = 1; i < argc; i++) {
93
pattern[i - 1] = xstrfmt("*/%s", argv[i]);
94
}
builtin/merge.c
+1
-1
@@ -210,7 +210,7 @@ static struct strategy *get_strategy(const char *name)
210
exit(1);
211
}
212
213
- ret = xcalloc(1, sizeof(struct strategy));
213
+ CALLOC_ARRAY(ret, 1);
214
ret->name = xstrdup(name);
215
ret->attr = NO_TRIVIAL;
216
return ret;
builtin/notes.c
+1
-1
@@ -730,7 +730,7 @@ static int merge_commit(struct notes_merge_options *o)
730
else
731
oidclr(&parent_oid);
732
733
- t = xcalloc(1, sizeof(struct notes_tree));
733
+ CALLOC_ARRAY(t, 1);
734
init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
735
736
o->local_ref = local_ref_to_free =
builtin/pack-objects.c
+4
-4
@@ -1635,7 +1635,7 @@ static void add_preferred_base(struct object_id *oid)
1635
}
1636
}
1637
1638
- it = xcalloc(1, sizeof(*it));
1638
+ CALLOC_ARRAY(it, 1);
1639
it->next = pbase_tree;
1640
pbase_tree = it;
1641
@@ -2096,7 +2096,7 @@ static void get_object_details(void)
2096
progress_state = start_progress(_("Counting objects"),
2097
to_pack.nr_objects);
2098
2099
- sorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *));
2099
+ CALLOC_ARRAY(sorted_by_offset, to_pack.nr_objects);
2100
for (i = 0; i < to_pack.nr_objects; i++)
2101
sorted_by_offset[i] = to_pack.objects + i;
2102
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,
2428
struct unpacked *array;
2429
unsigned long mem_usage = 0;
2430
2431
- array = xcalloc(window, sizeof(struct unpacked));
2431
+ CALLOC_ARRAY(array, window);
2432
2433
for (;;) {
2434
struct object_entry *entry;
@@ -2665,7 +2665,7 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,
2665
if (progress > pack_to_stdout)
2666
fprintf_ln(stderr, _("Delta compression using up to %d threads"),
2667
delta_search_threads);
2668
- p = xcalloc(delta_search_threads, sizeof(*p));
2668
+ CALLOC_ARRAY(p, delta_search_threads);
2669
2670
/* Partition the work amongst work threads. */
2671
for (i = 0; i < delta_search_threads; i++) {
builtin/pack-redundant.c
+1
-1
@@ -373,7 +373,7 @@ static void sort_pack_list(struct pack_list **pl)
373
return;
374
375
/* prepare an array of packed_list for easier sorting */
376
- ary = xcalloc(n, sizeof(struct pack_list *));
376
+ CALLOC_ARRAY(ary, n);
377
for (n = 0, p = *pl; p; p = p->next)
378
ary[n++] = p;
379
builtin/receive-pack.c
+2
-2
@@ -358,7 +358,7 @@ static void proc_receive_ref_append(const char *prefix)
358
char *p;
359
int len;
360
361
- ref_pattern = xcalloc(1, sizeof(struct proc_receive_ref));
361
+ CALLOC_ARRAY(ref_pattern, 1);
362
p = strchr(prefix, ':');
363
if (p) {
364
while (prefix < p) {
@@ -1024,7 +1024,7 @@ static int read_proc_receive_report(struct packet_reader *reader,
1024
}
1025
if (new_report) {
1026
if (!hint->report) {
1027
- hint->report = xcalloc(1, sizeof(struct ref_push_report));
1027
+ CALLOC_ARRAY(hint->report, 1);
1028
report = hint->report;
1029
} else {
1030
report = hint->report;
builtin/unpack-objects.c
+2
-2
@@ -46,7 +46,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base)
46
static void add_object_buffer(struct object *object, char *buffer, unsigned long size)
47
{
48
struct obj_buffer *obj;
49
- obj = xcalloc(1, sizeof(struct obj_buffer));
49
+ CALLOC_ARRAY(obj, 1);
50
obj->buffer = buffer;
51
obj->size = size;
52
if (add_decoration(&obj_decorate, object, obj))
@@ -500,7 +500,7 @@ static void unpack_all(void)
500
501
if (!quiet)
502
progress = start_progress(_("Unpacking objects"), nr_objects);
503
- obj_list = xcalloc(nr_objects, sizeof(*obj_list));
503
+ CALLOC_ARRAY(obj_list, nr_objects);
504
for (i = 0; i < nr_objects; i++) {
505
unpack_one(i);
506
display_progress(progress, i + 1);
bulk-checkin.c
+1
-1
@@ -211,7 +211,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,
211
212
/* Note: idx is non-NULL when we are writing */
213
if ((flags & HASH_WRITE_OBJECT) != 0)
214
- idx = xcalloc(1, sizeof(*idx));
214
+ CALLOC_ARRAY(idx, 1);
215
216
already_hashed_to = 0;
217
cache-tree.c
+1
-1
@@ -564,7 +564,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
564
* hence +2.
565
*/
566
it->subtree_alloc = subtree_nr + 2;
567
- it->down = xcalloc(it->subtree_alloc, sizeof(struct cache_tree_sub *));
567
+ CALLOC_ARRAY(it->down, it->subtree_alloc);
568
for (i = 0; i < subtree_nr; i++) {
569
/* read each subtree */
570
struct cache_tree *sub;
combine-diff.c
+10
-10
@@ -214,11 +214,11 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
214
* - Else if we have NEW, insert newend lline into base and
215
* consume newend
216
*/
217
- lcs = xcalloc(st_add(origbaselen, 1), sizeof(int*));
218
- directions = xcalloc(st_add(origbaselen, 1), sizeof(enum coalesce_direction*));
217
+ CALLOC_ARRAY(lcs, st_add(origbaselen, 1));
218
+ CALLOC_ARRAY(directions, st_add(origbaselen, 1));
219
for (i = 0; i < origbaselen + 1; i++) {
220
- lcs[i] = xcalloc(st_add(lennew, 1), sizeof(int));
221
- directions[i] = xcalloc(st_add(lennew, 1), sizeof(enum coalesce_direction));
220
+ CALLOC_ARRAY(lcs[i], st_add(lennew, 1));
221
+ CALLOC_ARRAY(directions[i], st_add(lennew, 1));
222
directions[i][0] = BASE;
223
}
224
for (j = 1; j < lennew + 1; j++)
@@ -398,8 +398,8 @@ static void consume_hunk(void *state_,
398
state->lost_bucket = &state->sline[state->nb-1];
399
}
400
if (!state->sline[state->nb-1].p_lno)
401
- state->sline[state->nb-1].p_lno =
402
- xcalloc(state->num_parent, sizeof(unsigned long));
401
+ CALLOC_ARRAY(state->sline[state->nb - 1].p_lno,
402
+ state->num_parent);
403
state->sline[state->nb-1].p_lno[state->n] = state->ob;
404
}
405
@@ -1159,7 +1159,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1159
if (result_size && result[result_size-1] != '\n')
1160
cnt++; /* incomplete line */
1161
1162
- sline = xcalloc(st_add(cnt, 2), sizeof(*sline));
1162
+ CALLOC_ARRAY(sline, st_add(cnt, 2));
1163
sline[0].bol = result;
1164
for (lno = 0, cp = result; cp < result + result_size; cp++) {
1165
if (*cp == '\n') {
@@ -1178,7 +1178,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1178
/* Even p_lno[cnt+1] is valid -- that is for the end line number
1179
* for deletion hunk at the end.
1180
*/
1181
- sline[0].p_lno = xcalloc(st_mult(st_add(cnt, 2), num_parent), sizeof(unsigned long));
1181
+ CALLOC_ARRAY(sline[0].p_lno, st_mult(st_add(cnt, 2), num_parent));
1182
for (lno = 0; lno <= cnt; lno++)
1183
sline[lno+1].p_lno = sline[lno].p_lno + num_parent;
1184
@@ -1319,7 +1319,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
1319
struct diff_filespec *pool;
1320
1321
pair = xmalloc(sizeof(*pair));
1322
- pool = xcalloc(st_add(num_parent, 1), sizeof(struct diff_filespec));
1322
+ CALLOC_ARRAY(pool, st_add(num_parent, 1));
1323
pair->one = pool + 1;
1324
pair->two = pool;
1325
@@ -1348,7 +1348,7 @@ static void handle_combined_callback(struct diff_options *opt,
1348
struct diff_queue_struct q;
1349
int i;
1350
1351
- q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));
1351
+ CALLOC_ARRAY(q.queue, num_paths);
1352
q.alloc = num_paths;
1353
q.nr = num_paths;
1354
for (i = 0, p = paths; p; p = p->next)
commit-graph.c
+2
-2
@@ -516,7 +516,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
516
return NULL;
517
518
count = st.st_size / (the_hash_algo->hexsz + 1);
519
- oids = xcalloc(count, sizeof(struct object_id));
519
+ CALLOC_ARRAY(oids, count);
520
521
prepare_alt_odb(r);
522
@@ -2238,7 +2238,7 @@ int write_commit_graph(struct object_directory *odb,
2238
if (!commit_graph_compatible(the_repository))
2239
return 0;
2240
2241
- ctx = xcalloc(1, sizeof(struct write_commit_graph_context));
2241
+ CALLOC_ARRAY(ctx, 1);
2242
ctx->r = the_repository;
2243
ctx->odb = odb;
2244
ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
commit-reach.c
+3
-3
@@ -183,7 +183,7 @@ static int remove_redundant_no_gen(struct repository *r,
183
int *filled_index;
184
int i, j, filled;
185
186
- work = xcalloc(cnt, sizeof(*work));
186
+ CALLOC_ARRAY(work, cnt);
187
redundant = xcalloc(cnt, 1);
188
ALLOC_ARRAY(filled_index, cnt - 1);
189
@@ -399,7 +399,7 @@ static struct commit_list *get_merge_bases_many_0(struct repository *r,
399
400
/* There are more than one */
401
cnt = commit_list_count(result);
402
- rslt = xcalloc(cnt, sizeof(*rslt));
402
+ CALLOC_ARRAY(rslt, cnt);
403
for (list = result, i = 0; list; list = list->next)
404
rslt[i++] = list->item;
405
free_commit_list(result);
@@ -541,7 +541,7 @@ struct commit_list *reduce_heads(struct commit_list *heads)
541
p->item->object.flags |= STALE;
542
num_head++;
543
}
544
- array = xcalloc(num_head, sizeof(*array));
544
+ CALLOC_ARRAY(array, num_head);
545
for (p = heads, i = 0; p; p = p->next) {
546
if (p->item->object.flags & STALE) {
547
array[i++] = p->item;
commit.c
+2
-2
@@ -1171,7 +1171,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
1171
* if (verify_signed_buffer(buf, len, buf + len, size - len, ...))
1172
* warn("warning: signed tag unverified.");
1173
*/
1174
- mergetag = xcalloc(1, sizeof(*mergetag));
1174
+ CALLOC_ARRAY(mergetag, 1);
1175
mergetag->key = xstrdup("mergetag");
1176
mergetag->value = buf;
1177
mergetag->len = size;
@@ -1336,7 +1336,7 @@ static struct commit_extra_header *read_commit_extra_header_lines(
1336
excluded_header_field(line, eof - line, exclude))
1337
continue;
1338
1339
- it = xcalloc(1, sizeof(*it));
1339
+ CALLOC_ARRAY(it, 1);
1340
it->key = xmemdupz(line, eof-line);
1341
*tail = it;
1342
tail = &it->next;
config.c
+1
-1
@@ -2269,7 +2269,7 @@ static void repo_read_config(struct repository *repo)
2269
opts.git_dir = repo->gitdir;
2270
2271
if (!repo->config)
2272
- repo->config = xcalloc(1, sizeof(struct config_set));
2272
+ CALLOC_ARRAY(repo->config, 1);
2273
else
2274
git_configset_clear(repo->config);
2275
contrib/coccinelle/array.cocci
+8
@@ -88,3 +88,11 @@ expression n;
88
@@
89
- ptr = xmalloc((n) * sizeof(T));
90
+ ALLOC_ARRAY(ptr, n);
91
+
92
+@@
93
+type T;
94
+T *ptr;
95
+expression n;
96
+@@
97
+- ptr = xcalloc(n, \( sizeof(*ptr) \| sizeof(T) \) )
98
++ CALLOC_ARRAY(ptr, n)
convert.c
+1
-1
@@ -1028,7 +1028,7 @@ static int read_convert_config(const char *var, const char *value, void *cb)
1028
if (!strncmp(drv->name, name, namelen) && !drv->name[namelen])
1029
break;
1030
if (!drv) {
1031
- drv = xcalloc(1, sizeof(struct convert_driver));
1031
+ CALLOC_ARRAY(drv, 1);
1032
drv->name = xmemdupz(name, namelen);
1033
*user_convert_tail = drv;
1034
user_convert_tail = &(drv->next);
daemon.c
+2
-2
@@ -840,7 +840,7 @@ static void add_child(struct child_process *cld, struct sockaddr *addr, socklen_
840
{
841
struct child *newborn, **cradle;
842
843
- newborn = xcalloc(1, sizeof(*newborn));
843
+ CALLOC_ARRAY(newborn, 1);
844
live_children++;
845
memcpy(&newborn->cld, cld, sizeof(*cld));
846
memcpy(&newborn->address, addr, addrlen);
@@ -1148,7 +1148,7 @@ static int service_loop(struct socketlist *socklist)
1148
struct pollfd *pfd;
1149
int i;
1150
1151
- pfd = xcalloc(socklist->nr, sizeof(struct pollfd));
1151
+ CALLOC_ARRAY(pfd, socklist->nr);
1152
1153
for (i = 0; i < socklist->nr; i++) {
1154
pfd[i].fd = socklist->list[i];
decorate.c
+1
-1
@@ -39,7 +39,7 @@ static void grow_decoration(struct decoration *n)
39
struct decoration_entry *old_entries = n->entries;
40
41
n->size = (old_size + 1000) * 3 / 2;
42
- n->entries = xcalloc(n->size, sizeof(struct decoration_entry));
42
+ CALLOC_ARRAY(n->entries, n->size);
43
n->nr = 0;
44
45
for (i = 0; i < old_size; i++) {
diff.c
+4
-6
@@ -2233,14 +2233,12 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
2233
struct diff_options *o = xmalloc(sizeof(struct diff_options));
2234
memcpy(o, orig_opts, sizeof(struct diff_options));
2235
2236
- ecbdata->diff_words =
2237
- xcalloc(1, sizeof(struct diff_words_data));
2236
+ CALLOC_ARRAY(ecbdata->diff_words, 1);
2237
ecbdata->diff_words->type = o->word_diff;
2238
ecbdata->diff_words->opt = o;
2239
2240
if (orig_opts->emitted_symbols)
2242
- o->emitted_symbols =
2243
- xcalloc(1, sizeof(struct emitted_diff_symbols));
2241
+ CALLOC_ARRAY(o->emitted_symbols, 1);
2242
2243
if (!o->word_regex)
2244
o->word_regex = userdiff_word_regex(one, o->repo->index);
@@ -2509,7 +2507,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
2507
const char *name_b)
2508
{
2509
struct diffstat_file *x;
2512
- x = xcalloc(1, sizeof(*x));
2510
+ CALLOC_ARRAY(x, 1);
2511
ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc);
2512
diffstat->files[diffstat->nr++] = x;
2513
if (name_b) {
@@ -4918,7 +4916,7 @@ static int diff_opt_find_object(const struct option *option,
4916
return error(_("unable to resolve '%s'"), arg);
4917
4918
if (!opt->objfind)
4921
- opt->objfind = xcalloc(1, sizeof(*opt->objfind));
4919
+ CALLOC_ARRAY(opt->objfind, 1);
4920
4921
opt->pickaxe_opts |= DIFF_PICKAXE_KIND_OBJFIND;
4922
opt->flags.recursive = 1;
diffcore-rename.c
+1
-2
@@ -787,8 +787,7 @@ void diffcore_rename(struct diff_options *options)
787
(uint64_t)num_destinations * (uint64_t)num_sources);
788
}
789
790
- mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_destinations),
791
- sizeof(*mx));
790
+ CALLOC_ARRAY(mx, st_mult(NUM_CANDIDATE_PER_DST, num_destinations));
791
for (dst_cnt = i = 0; i < rename_dst_nr; i++) {
792
struct diff_filespec *two = rename_dst[i].p->two;
793
struct diff_score *m;
dir.c
+3
-3
@@ -1488,7 +1488,7 @@ static void prep_exclude(struct dir_struct *dir,
1488
const char *cp;
1489
struct oid_stat oid_stat;
1490
1491
- stk = xcalloc(1, sizeof(*stk));
1491
+ CALLOC_ARRAY(stk, 1);
1492
if (current < 0) {
1493
cp = base;
1494
current = 0;
@@ -3162,7 +3162,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
3162
int varint_len;
3163
const unsigned hashsz = the_hash_algo->rawsz;
3164
3165
- ouc = xcalloc(1, sizeof(*ouc));
3165
+ CALLOC_ARRAY(ouc, 1);
3166
stat_data_to_disk(&ouc->info_exclude_stat, &untracked->ss_info_exclude.stat);
3167
stat_data_to_disk(&ouc->excludes_file_stat, &untracked->ss_excludes_file.stat);
3168
ouc->dir_flags = htonl(untracked->dir_flags);
@@ -3373,7 +3373,7 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
3373
if (next + exclude_per_dir_offset + 1 > end)
3374
return NULL;
3375
3376
- uc = xcalloc(1, sizeof(*uc));
3376
+ CALLOC_ARRAY(uc, 1);
3377
strbuf_init(&uc->ident, ident_len);
3378
strbuf_add(&uc->ident, ident, ident_len);
3379
load_oid_stat(&uc->ss_info_exclude,
ewah/bitmap.c
+1
-1
@@ -25,7 +25,7 @@
25
struct bitmap *bitmap_word_alloc(size_t word_alloc)
26
{
27
struct bitmap *bitmap = xmalloc(sizeof(struct bitmap));
28
- bitmap->words = xcalloc(word_alloc, sizeof(eword_t));
28
+ CALLOC_ARRAY(bitmap->words, word_alloc);
29
bitmap->word_alloc = word_alloc;
30
return bitmap;
31
}
fetch-pack.c
+1
-1
@@ -1916,7 +1916,7 @@ static void update_shallow(struct fetch_pack_args *args,
1916
* remote is also shallow, check what ref is safe to update
1917
* without updating .git/shallow
1918
*/
1919
- status = xcalloc(nr_sought, sizeof(*status));
1919
+ CALLOC_ARRAY(status, nr_sought);
1920
assign_shallow_commits_to_refs(si, NULL, status);
1921
if (si->nr_ours || si->nr_theirs) {
1922
for (i = 0; i < nr_sought; i++)
fmt-merge-msg.c
+1
-1
@@ -130,7 +130,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
130
if (!find_merge_parent(merge_parents, &oid, NULL))
131
return 0; /* subsumed by other parents */
132
133
- origin_data = xcalloc(1, sizeof(struct origin_data));
133
+ CALLOC_ARRAY(origin_data, 1);
134
oidcpy(&origin_data->oid, &oid);
135
136
if (line[len - 1] == '\n')
grep.c
+4
-4
@@ -621,7 +621,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
621
case GREP_PATTERN: /* atom */
622
case GREP_PATTERN_HEAD:
623
case GREP_PATTERN_BODY:
624
- x = xcalloc(1, sizeof (struct grep_expr));
624
+ CALLOC_ARRAY(x, 1);
625
x->node = GREP_NODE_ATOM;
626
x->u.atom = p;
627
*list = p->next;
@@ -651,7 +651,7 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
651
if (!p->next)
652
die("--not not followed by pattern expression");
653
*list = p->next;
654
- x = xcalloc(1, sizeof (struct grep_expr));
654
+ CALLOC_ARRAY(x, 1);
655
x->node = GREP_NODE_NOT;
656
x->u.unary = compile_pattern_not(list);
657
if (!x->u.unary)
@@ -676,7 +676,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
676
y = compile_pattern_and(list);
677
if (!y)
678
die("--and not followed by pattern expression");
679
- z = xcalloc(1, sizeof (struct grep_expr));
679
+ CALLOC_ARRAY(z, 1);
680
z->node = GREP_NODE_AND;
681
z->u.binary.left = x;
682
z->u.binary.right = y;
@@ -696,7 +696,7 @@ static struct grep_expr *compile_pattern_or(struct grep_pat **list)
696
y = compile_pattern_or(list);
697
if (!y)
698
die("not a pattern expression %s", p->pattern);
699
- z = xcalloc(1, sizeof (struct grep_expr));
699
+ CALLOC_ARRAY(z, 1);
700
z->node = GREP_NODE_OR;
701
z->u.binary.left = x;
702
z->u.binary.right = y;
hashmap.c
+1
-1
@@ -76,7 +76,7 @@ unsigned int memihash_cont(unsigned int hash_seed, const void *buf, size_t len)
76
static void alloc_table(struct hashmap *map, unsigned int size)
77
{
78
map->tablesize = size;
79
- map->table = xcalloc(size, sizeof(struct hashmap_entry *));
79
+ CALLOC_ARRAY(map->table, size);
80
81
/* calculate resize thresholds for new size */
82
map->grow_at = (unsigned int) ((uint64_t) size * HASHMAP_LOAD_FACTOR / 100);
http-backend.c
+1
-1
@@ -39,7 +39,7 @@ static struct string_list *get_parameters(void)
39
if (!query_params) {
40
const char *query = getenv("QUERY_STRING");
41
42
- query_params = xcalloc(1, sizeof(*query_params));
42
+ CALLOC_ARRAY(query_params, 1);
43
while (query && *query) {
44
char *name = url_decode_parameter_name(&query);
45
char *value = url_decode_parameter_value(&query);
http-push.c
+2
-2
@@ -896,7 +896,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
896
curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
897
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
898
899
- lock = xcalloc(1, sizeof(*lock));
899
+ CALLOC_ARRAY(lock, 1);
900
lock->timeout = -1;
901
902
if (start_active_slot(slot)) {
@@ -1713,7 +1713,7 @@ int cmd_main(int argc, const char **argv)
1713
int new_refs;
1714
struct ref *ref, *local_refs;
1715
1716
- repo = xcalloc(1, sizeof(*repo));
1716
+ CALLOC_ARRAY(repo, 1);
1717
1718
argv++;
1719
for (i = 1; i < argc; i++, argv++) {
http.c
+2
-2
@@ -2324,7 +2324,7 @@ struct http_pack_request *new_direct_http_pack_request(
2324
off_t prev_posn = 0;
2325
struct http_pack_request *preq;
2326
2327
- preq = xcalloc(1, sizeof(*preq));
2327
+ CALLOC_ARRAY(preq, 1);
2328
strbuf_init(&preq->tmpfile, 0);
2329
2330
preq->url = url;
@@ -2419,7 +2419,7 @@ struct http_object_request *new_http_object_request(const char *base_url,
2419
off_t prev_posn = 0;
2420
struct http_object_request *freq;
2421
2422
- freq = xcalloc(1, sizeof(*freq));
2422
+ CALLOC_ARRAY(freq, 1);
2423
strbuf_init(&freq->tmpfile, 0);
2424
oidcpy(&freq->oid, oid);
2425
freq->localfile = -1;
imap-send.c
+2
-2
@@ -963,9 +963,9 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const c
963
char *arg, *rsp;
964
int s = -1, preauth;
965
966
- ctx = xcalloc(1, sizeof(*ctx));
966
+ CALLOC_ARRAY(ctx, 1);
967
968
- ctx->imap = imap = xcalloc(1, sizeof(*imap));
968
+ ctx->imap = CALLOC_ARRAY(imap, 1);
969
imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;
970
imap->in_progress_append = &imap->in_progress;
971
line-log.c
+1
-1
@@ -296,7 +296,7 @@ static void line_log_data_insert(struct line_log_data **list,
296
return;
297
}
298
299
- p = xcalloc(1, sizeof(struct line_log_data));
299
+ CALLOC_ARRAY(p, 1);
300
p->path = path;
301
range_set_append(&p->ranges, begin, end);
302
if (ip) {
line-range.c
+1
-1
@@ -202,7 +202,7 @@ static const char *parse_range_funcname(
202
drv = userdiff_find_by_path(istate, path);
203
if (drv && drv->funcname.pattern) {
204
const struct userdiff_funcname *pe = &drv->funcname;
205
- xecfg = xcalloc(1, sizeof(*xecfg));
205
+ CALLOC_ARRAY(xecfg, 1);
206
xdiff_set_find_func(xecfg, pe->pattern, pe->cflags);
207
}
208
list-objects-filter.c
+3
-3
@@ -186,7 +186,7 @@ static enum list_objects_filter_result filter_trees_depth(
186
seen_info = oidmap_get(
187
&filter_data->seen_at_depth, &obj->oid);
188
if (!seen_info) {
189
- seen_info = xcalloc(1, sizeof(*seen_info));
189
+ CALLOC_ARRAY(seen_info, 1);
190
oidcpy(&seen_info->base.oid, &obj->oid);
191
seen_info->depth = filter_data->current_depth;
192
oidmap_put(&filter_data->seen_at_depth, seen_info);
@@ -626,7 +626,7 @@ static void filter_combine__init(
626
size_t sub;
627
628
d->nr = filter_options->sub_nr;
629
- d->sub = xcalloc(d->nr, sizeof(*d->sub));
629
+ CALLOC_ARRAY(d->sub, d->nr);
630
for (sub = 0; sub < d->nr; sub++)
631
d->sub[sub].filter = list_objects_filter__init(
632
filter->omits ? &d->sub[sub].omits : NULL,
@@ -674,7 +674,7 @@ struct filter *list_objects_filter__init(
674
if (!init_fn)
675
return NULL;
676
677
- filter = xcalloc(1, sizeof(*filter));
677
+ CALLOC_ARRAY(filter, 1);
678
filter->omits = omitted;
679
init_fn(filter_options, filter);
680
return filter;
ll-merge.c
+1
-1
@@ -268,7 +268,7 @@ static int read_merge_config(const char *var, const char *value, void *cb)
268
if (!strncmp(fn->name, name, namelen) && !fn->name[namelen])
269
break;
270
if (!fn) {
271
- fn = xcalloc(1, sizeof(struct ll_merge_driver));
271
+ CALLOC_ARRAY(fn, 1);
272
fn->name = xmemdupz(name, namelen);
273
fn->fn = ll_ext_merge;
274
*ll_user_merge_tail = fn;
mailmap.c
+1
-1
@@ -83,7 +83,7 @@ static void add_mapping(struct string_list *map,
83
if (item->util) {
84
me = (struct mailmap_entry *)item->util;
85
} else {
86
- me = xcalloc(1, sizeof(struct mailmap_entry));
86
+ CALLOC_ARRAY(me, 1);
87
me->namemap.strdup_strings = 1;
88
me->namemap.cmp = namemap_cmp;
89
item->util = me;
merge-ort.c
+4
-5
@@ -1576,8 +1576,7 @@ static void compute_collisions(struct strmap *collisions,
1576
if (collision_info) {
1577
free(new_path);
1578
} else {
1579
- collision_info = xcalloc(1,
1580
- sizeof(struct collision_info));
1579
+ CALLOC_ARRAY(collision_info, 1);
1580
string_list_init(&collision_info->source_files, 0);
1581
strmap_put(collisions, new_path, collision_info);
1582
}
@@ -1718,7 +1717,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
1717
struct conflict_info *dir_ci;
1718
char *cur_dir = dirs_to_insert.items[i].string;
1719
1721
- dir_ci = xcalloc(1, sizeof(*dir_ci));
1720
+ CALLOC_ARRAY(dir_ci, 1);
1721
1722
dir_ci->merged.directory_name = parent_name;
1723
len = strlen(parent_name);
@@ -2703,7 +2702,7 @@ static void process_entry(struct merge_options *opt,
2702
* the directory to remain here, so we need to move this
2703
* path to some new location.
2704
*/
2706
- new_ci = xcalloc(1, sizeof(*new_ci));
2705
+ CALLOC_ARRAY(new_ci, 1);
2706
/* We don't really want new_ci->merged.result copied, but it'll
2707
* be overwritten below so it doesn't matter. We also don't
2708
* want any directory mode/oid values copied, but we'll zero
@@ -3083,7 +3082,7 @@ static int checkout(struct merge_options *opt,
3082
unpack_opts.verbose_update = (opt->verbosity > 2);
3083
unpack_opts.fn = twoway_merge;
3084
if (1/* FIXME: opts->overwrite_ignore*/) {
3086
- unpack_opts.dir = xcalloc(1, sizeof(*unpack_opts.dir));
3085
+ CALLOC_ARRAY(unpack_opts.dir, 1);
3086
unpack_opts.dir->flags |= DIR_SHOW_IGNORED;
3087
setup_standard_excludes(unpack_opts.dir);
3088
}
merge-recursive.c
+4
-5
@@ -303,7 +303,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
303
return;
304
}
305
306
- ci = xcalloc(1, sizeof(struct rename_conflict_info));
306
+ CALLOC_ARRAY(ci, 1);
307
ci->rename_type = rename_type;
308
ci->ren1 = ren1;
309
ci->ren2 = ren2;
@@ -2389,8 +2389,7 @@ static void compute_collisions(struct hashmap *collisions,
2389
continue;
2390
collision_ent = collision_find_entry(collisions, new_path);
2391
if (!collision_ent) {
2392
- collision_ent = xcalloc(1,
2393
- sizeof(struct collision_entry));
2392
+ CALLOC_ARRAY(collision_ent, 1);
2393
hashmap_entry_init(&collision_ent->ent,
2394
strhash(new_path));
2395
hashmap_put(collisions, &collision_ent->ent);
@@ -2594,7 +2593,7 @@ static struct string_list *get_renames(struct merge_options *opt,
2593
struct string_list *renames;
2594
2595
compute_collisions(&collisions, dir_renames, pairs);
2597
- renames = xcalloc(1, sizeof(struct string_list));
2596
+ CALLOC_ARRAY(renames, 1);
2597
2598
for (i = 0; i < pairs->nr; ++i) {
2599
struct string_list_item *item;
@@ -3664,7 +3663,7 @@ static int merge_start(struct merge_options *opt, struct tree *head)
3663
return -1;
3664
}
3665
3667
- opt->priv = xcalloc(1, sizeof(*opt->priv));
3666
+ CALLOC_ARRAY(opt->priv, 1);
3667
string_list_init(&opt->priv->df_conflict_file_set, 1);
3668
return 0;
3669
}
midx.c
+4
-4
@@ -145,8 +145,8 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
145
146
m->num_objects = ntohl(m->chunk_oid_fanout[255]);
147
148
- m->pack_names = xcalloc(m->num_packs, sizeof(*m->pack_names));
149
- m->packs = xcalloc(m->num_packs, sizeof(*m->packs));
148
+ CALLOC_ARRAY(m->pack_names, m->num_packs);
149
+ CALLOC_ARRAY(m->packs, m->num_packs);
150
151
cur_pack_name = (const char *)m->chunk_pack_names;
152
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
1144
if (!m)
1145
return 0;
1146
1147
- count = xcalloc(m->num_packs, sizeof(uint32_t));
1147
+ CALLOC_ARRAY(count, m->num_packs);
1148
1149
if (flags & MIDX_PROGRESS)
1150
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,
1315
if (!m)
1316
return 0;
1317
1318
- include_pack = xcalloc(m->num_packs, sizeof(unsigned char));
1318
+ CALLOC_ARRAY(include_pack, m->num_packs);
1319
1320
if (batch_size) {
1321
if (fill_included_packs_batch(r, m, include_pack, batch_size))
name-hash.c
+4
-4
@@ -225,7 +225,7 @@ static void init_dir_mutex(void)
225
{
226
int j;
227
228
- lazy_dir_mutex_array = xcalloc(LAZY_MAX_MUTEX, sizeof(pthread_mutex_t));
228
+ CALLOC_ARRAY(lazy_dir_mutex_array, LAZY_MAX_MUTEX);
229
230
for (j = 0; j < LAZY_MAX_MUTEX; j++)
231
init_recursive_mutex(&lazy_dir_mutex_array[j]);
@@ -514,9 +514,9 @@ static void threaded_lazy_init_name_hash(
514
k_start = 0;
515
nr_each = DIV_ROUND_UP(istate->cache_nr, lazy_nr_dir_threads);
516
517
- lazy_entries = xcalloc(istate->cache_nr, sizeof(struct lazy_entry));
518
- td_dir = xcalloc(lazy_nr_dir_threads, sizeof(struct lazy_dir_thread_data));
519
- td_name = xcalloc(1, sizeof(struct lazy_name_thread_data));
517
+ CALLOC_ARRAY(lazy_entries, istate->cache_nr);
518
+ CALLOC_ARRAY(td_dir, lazy_nr_dir_threads);
519
+ CALLOC_ARRAY(td_name, 1);
520
521
init_dir_mutex();
522
negotiator/default.c
+1
-1
@@ -167,7 +167,7 @@ void default_negotiator_init(struct fetch_negotiator *negotiator)
167
negotiator->next = next;
168
negotiator->ack = ack;
169
negotiator->release = release;
170
- negotiator->data = ns = xcalloc(1, sizeof(*ns));
170
+ negotiator->data = CALLOC_ARRAY(ns, 1);
171
ns->rev_list.compare = compare_commits_by_commit_date;
172
173
if (marked)
negotiator/skipping.c
+2
-2
@@ -62,7 +62,7 @@ static struct entry *rev_list_push(struct data *data, struct commit *commit, int
62
struct entry *entry;
63
commit->object.flags |= mark | SEEN;
64
65
- entry = xcalloc(1, sizeof(*entry));
65
+ CALLOC_ARRAY(entry, 1);
66
entry->commit = commit;
67
prio_queue_put(&data->rev_list, entry);
68
@@ -241,7 +241,7 @@ void skipping_negotiator_init(struct fetch_negotiator *negotiator)
241
negotiator->next = next;
242
negotiator->ack = ack;
243
negotiator->release = release;
244
- negotiator->data = data = xcalloc(1, sizeof(*data));
244
+ negotiator->data = CALLOC_ARRAY(data, 1);
245
data->rev_list.compare = compare;
246
247
if (marked)
notes-merge.c
+1
-1
@@ -136,7 +136,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
136
diff_tree_oid(base, remote, "", &opt);
137
diffcore_std(&opt);
138
139
- changes = xcalloc(diff_queued_diff.nr, sizeof(struct notes_merge_pair));
139
+ CALLOC_ARRAY(changes, diff_queued_diff.nr);
140
141
for (i = 0; i < diff_queued_diff.nr; i++) {
142
struct diff_filepair *p = diff_queued_diff.queue[i];
notes-utils.c
+1
-1
@@ -129,7 +129,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
129
c->cmd = cmd;
130
c->enabled = 1;
131
c->combine = combine_notes_concatenate;
132
- c->refs = xcalloc(1, sizeof(struct string_list));
132
+ CALLOC_ARRAY(c->refs, 1);
133
c->refs->strdup_strings = 1;
134
c->refs_from_env = 0;
135
c->mode_from_env = 0;
notes.c
+1
-1
@@ -452,7 +452,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
452
goto handle_non_note;
453
}
454
455
- l = xcalloc(1, sizeof(*l));
455
+ CALLOC_ARRAY(l, 1);
456
oidcpy(&l->key_oid, &object_oid);
457
oidcpy(&l->val_oid, &entry.oid);
458
if (note_tree_insert(t, node, n, l, type,
object-file.c
+1
-1
@@ -546,7 +546,7 @@ static int link_alt_odb_entry(struct repository *r, const char *entry,
546
return -1;
547
}
548
549
- ent = xcalloc(1, sizeof(*ent));
549
+ CALLOC_ARRAY(ent, 1);
550
ent->path = xstrdup(pathbuf.buf);
551
552
/* add the alternate entry */
object.c
+2
-2
@@ -127,7 +127,7 @@ static void grow_object_hash(struct repository *r)
127
int new_hash_size = r->parsed_objects->obj_hash_size < 32 ? 32 : 2 * r->parsed_objects->obj_hash_size;
128
struct object **new_hash;
129
130
- new_hash = xcalloc(new_hash_size, sizeof(struct object *));
130
+ CALLOC_ARRAY(new_hash, new_hash_size);
131
for (i = 0; i < r->parsed_objects->obj_hash_size; i++) {
132
struct object *obj = r->parsed_objects->obj_hash[i];
133
@@ -478,7 +478,7 @@ struct parsed_object_pool *parsed_object_pool_new(void)
478
o->object_state = allocate_alloc_state();
479
480
o->is_shallow = -1;
481
- o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
481
+ CALLOC_ARRAY(o->shallow_stat, 1);
482
483
o->buffer_slab = allocate_commit_buffer_slab();
484
pack-bitmap.c
+2
-2
@@ -978,7 +978,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
978
979
/* try to open a bitmapped pack, but don't parse it yet
980
* because we may not need to use it */
981
- bitmap_git = xcalloc(1, sizeof(*bitmap_git));
981
+ CALLOC_ARRAY(bitmap_git, 1);
982
if (open_pack_bitmap(revs->repo, bitmap_git) < 0)
983
goto cleanup;
984
@@ -1388,7 +1388,7 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
1388
uint32_t *reposition;
1389
1390
num_objects = bitmap_git->pack->num_objects;
1391
- reposition = xcalloc(num_objects, sizeof(uint32_t));
1391
+ CALLOC_ARRAY(reposition, num_objects);
1392
1393
for (i = 0; i < num_objects; ++i) {
1394
struct object_id oid;
pack-objects.c
+1
-1
@@ -49,7 +49,7 @@ static void rehash_objects(struct packing_data *pdata)
49
pdata->index_size = 1024;
50
51
free(pdata->index);
52
- pdata->index = xcalloc(pdata->index_size, sizeof(*pdata->index));
52
+ CALLOC_ARRAY(pdata->index, pdata->index_size);
53
54
entry = pdata->objects;
55
packfile.c
+1
-1
@@ -638,7 +638,7 @@ unsigned char *use_pack(struct packed_git *p,
638
if (p->pack_fd == -1 && open_packed_git(p))
639
die("packfile %s cannot be accessed", p->pack_name);
640
641
- win = xcalloc(1, sizeof(*win));
641
+ CALLOC_ARRAY(win, 1);
642
win->offset = (offset / window_align) * window_align;
643
len = p->pack_size - win->offset;
644
if (len > packed_git_window_size)
patch-ids.c
+1
-1
@@ -124,7 +124,7 @@ struct patch_id *add_commit_patch_id(struct commit *commit,
124
if (!patch_id_defined(commit))
125
return NULL;
126
127
- key = xcalloc(1, sizeof(*key));
127
+ CALLOC_ARRAY(key, 1);
128
if (init_patch_id_entry(key, commit, ids)) {
129
free(key);
130
return NULL;
pathspec.c
+2
-2
@@ -154,7 +154,7 @@ static void parse_pathspec_attr_match(struct pathspec_item *item, const char *va
154
string_list_remove_empty_items(&list, 0);
155
156
item->attr_check = attr_check_alloc();
157
- item->attr_match = xcalloc(list.nr, sizeof(struct attr_match));
157
+ CALLOC_ARRAY(item->attr_match, list.nr);
158
159
for_each_string_list_item(si, &list) {
160
size_t attr_len;
@@ -561,7 +561,7 @@ void parse_pathspec(struct pathspec *pathspec,
561
if (!(flags & PATHSPEC_PREFER_CWD))
562
BUG("PATHSPEC_PREFER_CWD requires arguments");
563
564
- pathspec->items = item = xcalloc(1, sizeof(*item));
564
+ pathspec->items = CALLOC_ARRAY(item, 1);
565
item->match = xstrdup(prefix);
566
item->original = xstrdup(prefix);
567
item->nowildcard_len = item->len = strlen(prefix);
pretty.c
+1
-1
@@ -678,7 +678,7 @@ static int mailmap_name(const char **email, size_t *email_len,
678
{
679
static struct string_list *mail_map;
680
if (!mail_map) {
681
- mail_map = xcalloc(1, sizeof(*mail_map));
681
+ CALLOC_ARRAY(mail_map, 1);
682
read_mailmap(mail_map);
683
}
684
return mail_map->nr && map_user(mail_map, email, email_len, name, name_len);
progress.c
+1
-1
@@ -196,7 +196,7 @@ void display_throughput(struct progress *progress, uint64_t total)
196
now_ns = progress_getnanotime(progress);
197
198
if (!tp) {
199
- progress->throughput = tp = xcalloc(1, sizeof(*tp));
199
+ progress->throughput = CALLOC_ARRAY(tp, 1);
200
tp->prev_total = tp->curr_total = total;
201
tp->prev_ns = now_ns;
202
strbuf_init(&tp->display, 0);
promisor-remote.c
+1
-1
@@ -208,7 +208,7 @@ static int remove_fetched_oids(struct repository *repo,
208
209
if (remaining_nr) {
210
int j = 0;
211
- new_oids = xcalloc(remaining_nr, sizeof(*new_oids));
211
+ CALLOC_ARRAY(new_oids, remaining_nr);
212
for (i = 0; i < oid_nr; i++)
213
if (remaining[i])
214
oidcpy(&new_oids[j++], &old_oids[i]);
range-diff.c
+1
-1
@@ -96,7 +96,7 @@ static int read_patches(const char *range, struct string_list *list,
96
string_list_append(list, buf.buf)->util = util;
97
strbuf_reset(&buf);
98
}
99
- util = xcalloc(sizeof(*util), 1);
99
+ CALLOC_ARRAY(util, 1);
100
if (get_oid(p, &util->oid)) {
101
error(_("could not parse commit '%s'"), p);
102
free(util);
read-cache.c
+4
-4
@@ -2097,7 +2097,7 @@ static unsigned long load_cache_entries_threaded(struct index_state *istate, con
2097
/* ensure we have no more threads than we have blocks to process */
2098
if (nr_threads > ieot->nr)
2099
nr_threads = ieot->nr;
2100
- data = xcalloc(nr_threads, sizeof(*data));
2100
+ CALLOC_ARRAY(data, nr_threads);
2101
2102
offset = ieot_start = 0;
2103
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)
2199
istate->version = ntohl(hdr->hdr_version);
2200
istate->cache_nr = ntohl(hdr->hdr_entries);
2201
istate->cache_alloc = alloc_nr(istate->cache_nr);
2202
- istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));
2202
+ CALLOC_ARRAY(istate->cache, istate->cache_alloc);
2203
istate->initialized = 1;
2204
2205
p.istate = istate;
@@ -2326,7 +2326,7 @@ int read_index_from(struct index_state *istate, const char *path,
2326
if (split_index->base)
2327
discard_index(split_index->base);
2328
else
2329
- split_index->base = xcalloc(1, sizeof(*split_index->base));
2329
+ CALLOC_ARRAY(split_index->base, 1);
2330
2331
base_oid_hex = oid_to_hex(&split_index->base_oid);
2332
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
@@ -3427,7 +3427,7 @@ void stat_validity_update(struct stat_validity *sv, int fd)
3427
stat_validity_clear(sv);
3428
else {
3429
if (!sv->sd)
3430
- sv->sd = xcalloc(1, sizeof(struct stat_data));
3430
+ CALLOC_ARRAY(sv->sd, 1);
3431
fill_stat_data(sv->sd, &st);
3432
}
3433
}
ref-filter.c
+3
-3
@@ -1676,7 +1676,7 @@ static int populate_value(struct ref_array_item *ref, struct strbuf *err)
1676
int i;
1677
struct object_info empty = OBJECT_INFO_INIT;
1678
1679
- ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));
1679
+ CALLOC_ARRAY(ref->value, used_atom_cnt);
1680
1681
if (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {
1682
ref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,
@@ -2185,7 +2185,7 @@ static void reach_filter(struct ref_array *array,
2185
if (!check_reachable)
2186
return;
2187
2188
- to_clear = xcalloc(sizeof(struct commit *), array->nr);
2188
+ CALLOC_ARRAY(to_clear, array->nr);
2189
2190
repo_init_revisions(the_repository, &revs, NULL);
2191
@@ -2490,7 +2490,7 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
2490
{
2491
struct ref_sorting *s;
2492
2493
- s = xcalloc(1, sizeof(*s));
2493
+ CALLOC_ARRAY(s, 1);
2494
s->next = *sorting_tail;
2495
*sorting_tail = s;
2496
reflog-walk.c
+2
-2
@@ -112,7 +112,7 @@ struct reflog_walk_info {
112
113
void init_reflog_walk(struct reflog_walk_info **info)
114
{
115
- *info = xcalloc(1, sizeof(struct reflog_walk_info));
115
+ CALLOC_ARRAY(*info, 1);
116
(*info)->complete_reflogs.strdup_strings = 1;
117
}
118
@@ -181,7 +181,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info,
181
}
182
free(branch);
183
184
- commit_reflog = xcalloc(1, sizeof(struct commit_reflog));
184
+ CALLOC_ARRAY(commit_reflog, 1);
185
if (recno < 0) {
186
commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp);
187
if (commit_reflog->recno < 0) {
refs.c
+2
-2
@@ -1007,7 +1007,7 @@ struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
1007
struct ref_transaction *tr;
1008
assert(err);
1009
1010
- tr = xcalloc(1, sizeof(struct ref_transaction));
1010
+ CALLOC_ARRAY(tr, 1);
1011
tr->ref_store = refs;
1012
return tr;
1013
}
@@ -1306,7 +1306,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
1306
while (len && ref[len - 1] == '/')
1307
ref[--len] = '\0';
1308
if (!hide_refs) {
1309
- hide_refs = xcalloc(1, sizeof(*hide_refs));
1309
+ CALLOC_ARRAY(hide_refs, 1);
1310
hide_refs->strdup_strings = 1;
1311
}
1312
string_list_append(hide_refs, ref);
refs/files-backend.c
+5
-5
@@ -549,7 +549,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
549
550
/* First lock the file so it can't change out from under us. */
551
552
- *lock_p = lock = xcalloc(1, sizeof(*lock));
552
+ *lock_p = CALLOC_ARRAY(lock, 1);
553
554
lock->ref_name = xstrdup(refname);
555
files_ref_path(refs, &ref_file, refname);
@@ -843,7 +843,7 @@ static struct ref_iterator *files_ref_iterator_begin(
843
844
overlay_iter = overlay_ref_iterator_begin(loose_iter, packed_iter);
845
846
- iter = xcalloc(1, sizeof(*iter));
846
+ CALLOC_ARRAY(iter, 1);
847
ref_iterator = &iter->base;
848
base_ref_iterator_init(ref_iterator, &files_ref_iterator_vtable,
849
overlay_iter->ordered);
@@ -930,7 +930,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
930
files_assert_main_repository(refs, "lock_ref_oid_basic");
931
assert(err);
932
933
- lock = xcalloc(1, sizeof(struct ref_lock));
933
+ CALLOC_ARRAY(lock, 1);
934
935
if (mustexist)
936
resolve_flags |= RESOLVE_REF_READING;
@@ -2152,7 +2152,7 @@ static struct ref_iterator *reflog_iterator_begin(struct ref_store *ref_store,
2152
return empty_ref_iterator_begin();
2153
}
2154
2155
- iter = xcalloc(1, sizeof(*iter));
2155
+ CALLOC_ARRAY(iter, 1);
2156
ref_iterator = &iter->base;
2157
2158
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,
2597
if (!transaction->nr)
2598
goto cleanup;
2599
2600
- backend_data = xcalloc(1, sizeof(*backend_data));
2600
+ CALLOC_ARRAY(backend_data, 1);
2601
transaction->backend_data = backend_data;
2602
2603
/*
refs/iterator.c
+1
-1
@@ -393,7 +393,7 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
393
if (!*prefix && !trim)
394
return iter0; /* optimization: no need to wrap iterator */
395
396
- iter = xcalloc(1, sizeof(*iter));
396
+ CALLOC_ARRAY(iter, 1);
397
ref_iterator = &iter->base;
398
399
base_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable, iter0->ordered);
refs/packed-backend.c
+2
-2
@@ -941,7 +941,7 @@ static struct ref_iterator *packed_ref_iterator_begin(
941
if (start == snapshot->eof)
942
return empty_ref_iterator_begin();
943
944
- iter = xcalloc(1, sizeof(*iter));
944
+ CALLOC_ARRAY(iter, 1);
945
ref_iterator = &iter->base;
946
base_ref_iterator_init(ref_iterator, &packed_ref_iterator_vtable, 1);
947
@@ -1424,7 +1424,7 @@ static int packed_transaction_prepare(struct ref_store *ref_store,
1424
* do so itself.
1425
*/
1426
1427
- data = xcalloc(1, sizeof(*data));
1427
+ CALLOC_ARRAY(data, 1);
1428
string_list_init(&data->updates, 0);
1429
1430
transaction->backend_data = data;
refs/ref-cache.c
+1
-1
@@ -530,7 +530,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
530
if (prime_dir)
531
prime_ref_dir(dir, prefix);
532
533
- iter = xcalloc(1, sizeof(*iter));
533
+ CALLOC_ARRAY(iter, 1);
534
ref_iterator = &iter->base;
535
base_ref_iterator_init(ref_iterator, &cache_ref_iterator_vtable, 1);
536
ALLOC_GROW(iter->levels, 10, iter->levels_alloc);
remote.c
+4
-4
@@ -151,7 +151,7 @@ static struct remote *make_remote(const char *name, int len)
151
if (e)
152
return container_of(e, struct remote, ent);
153
154
- ret = xcalloc(1, sizeof(struct remote));
154
+ CALLOC_ARRAY(ret, 1);
155
ret->prune = -1; /* unspecified */
156
ret->prune_tags = -1; /* unspecified */
157
ret->name = xstrndup(name, len);
@@ -186,7 +186,7 @@ static struct branch *make_branch(const char *name, size_t len)
186
}
187
188
ALLOC_GROW(branches, branches_nr + 1, branches_alloc);
189
- ret = xcalloc(1, sizeof(struct branch));
189
+ CALLOC_ARRAY(ret, 1);
190
branches[branches_nr++] = ret;
191
ret->name = xstrndup(name, len);
192
ret->refname = xstrfmt("refs/heads/%s", ret->name);
@@ -207,7 +207,7 @@ static struct rewrite *make_rewrite(struct rewrites *r,
207
}
208
209
ALLOC_GROW(r->rewrite, r->rewrite_nr + 1, r->rewrite_alloc);
210
- ret = xcalloc(1, sizeof(struct rewrite));
210
+ CALLOC_ARRAY(ret, 1);
211
r->rewrite[r->rewrite_nr++] = ret;
212
ret->base = xstrndup(base, len);
213
ret->baselen = len;
@@ -1664,7 +1664,7 @@ static void set_merge(struct branch *ret)
1664
1665
remote = remote_get(ret->remote_name);
1666
1667
- ret->merge = xcalloc(ret->merge_nr, sizeof(*ret->merge));
1667
+ CALLOC_ARRAY(ret->merge, ret->merge_nr);
1668
for (i = 0; i < ret->merge_nr; i++) {
1669
ret->merge[i] = xcalloc(1, sizeof(**ret->merge));
1670
ret->merge[i]->src = xstrdup(ret->merge_name[i]);
repository.c
+2
-2
@@ -72,7 +72,7 @@ void repo_set_gitdir(struct repository *repo,
72
repo_set_commondir(repo, o->commondir);
73
74
if (!repo->objects->odb) {
75
- repo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb));
75
+ CALLOC_ARRAY(repo->objects->odb, 1);
76
repo->objects->odb_tail = &repo->objects->odb->next;
77
}
78
expand_base_dir(&repo->objects->odb->path, o->object_dir,
@@ -262,7 +262,7 @@ void repo_clear(struct repository *repo)
262
int repo_read_index(struct repository *repo)
263
{
264
if (!repo->index)
265
- repo->index = xcalloc(1, sizeof(*repo->index));
265
+ CALLOC_ARRAY(repo->index, 1);
266
267
/* Complete the double-reference */
268
if (!repo->index->repo)
resolve-undo.c
+2
-2
@@ -15,7 +15,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)
15
return;
16
17
if (!istate->resolve_undo) {
18
- resolve_undo = xcalloc(1, sizeof(*resolve_undo));
18
+ CALLOC_ARRAY(resolve_undo, 1);
19
resolve_undo->strdup_strings = 1;
20
istate->resolve_undo = resolve_undo;
21
}
@@ -57,7 +57,7 @@ struct string_list *resolve_undo_read(const char *data, unsigned long size)
57
int i;
58
const unsigned rawsz = the_hash_algo->rawsz;
59
60
- resolve_undo = xcalloc(1, sizeof(*resolve_undo));
60
+ CALLOC_ARRAY(resolve_undo, 1);
61
resolve_undo->strdup_strings = 1;
62
63
while (size) {
revision.c
+3
-3
@@ -154,7 +154,7 @@ static void paths_and_oids_insert(struct hashmap *map,
154
155
entry = hashmap_get_entry(map, &key, ent, NULL);
156
if (!entry) {
157
- entry = xcalloc(1, sizeof(struct path_and_oids_entry));
157
+ CALLOC_ARRAY(entry, 1);
158
hashmap_entry_init(&entry->ent, hash);
159
entry->path = xstrdup(key.path);
160
oidset_init(&entry->trees, 16);
@@ -1555,7 +1555,7 @@ void clear_ref_exclusion(struct string_list **ref_excludes_p)
1555
void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)
1556
{
1557
if (!*ref_excludes_p) {
1558
- *ref_excludes_p = xcalloc(1, sizeof(**ref_excludes_p));
1558
+ CALLOC_ARRAY(*ref_excludes_p, 1);
1559
(*ref_excludes_p)->strdup_strings = 1;
1560
}
1561
string_list_append(*ref_excludes_p, exclude);
@@ -2929,7 +2929,7 @@ static struct merge_simplify_state *locate_simplify_state(struct rev_info *revs,
2929
2930
st = lookup_decoration(&revs->merge_simplification, &commit->object);
2931
if (!st) {
2932
- st = xcalloc(1, sizeof(*st));
2932
+ CALLOC_ARRAY(st, 1);
2933
add_decoration(&revs->merge_simplification, &commit->object, st);
2934
}
2935
return st;
run-command.c
+2
-2
@@ -1638,8 +1638,8 @@ static void pp_init(struct parallel_processes *pp,
1638
pp->nr_processes = 0;
1639
pp->output_owner = 0;
1640
pp->shutdown = 0;
1641
- pp->children = xcalloc(n, sizeof(*pp->children));
1642
- pp->pfd = xcalloc(n, sizeof(*pp->pfd));
1641
+ CALLOC_ARRAY(pp->children, n);
1642
+ CALLOC_ARRAY(pp->pfd, n);
1643
strbuf_init(&pp->buffered_output, 0);
1644
1645
for (i = 0; i < n; i++) {
send-pack.c
+2
-2
@@ -188,13 +188,13 @@ static int receive_status(struct packet_reader *reader, struct ref *refs)
188
}
189
if (new_report) {
190
if (!hint->report) {
191
- hint->report = xcalloc(1, sizeof(struct ref_push_report));
191
+ CALLOC_ARRAY(hint->report, 1);
192
report = hint->report;
193
} else {
194
report = hint->report;
195
while (report->next)
196
report = report->next;
197
- report->next = xcalloc(1, sizeof(struct ref_push_report));
197
+ CALLOC_ARRAY(report->next, 1);
198
report = report->next;
199
}
200
new_report = 0;
sequencer.c
+1
-1
@@ -5171,7 +5171,7 @@ void todo_list_add_exec_commands(struct todo_list *todo_list,
5171
int i, insert, nr = 0, alloc = 0;
5172
struct todo_item *items = NULL, *base_items = NULL;
5173
5174
- base_items = xcalloc(commands->nr, sizeof(struct todo_item));
5174
+ CALLOC_ARRAY(base_items, commands->nr);
5175
for (i = 0; i < commands->nr; i++) {
5176
size_t command_len = strlen(commands->items[i].string);
5177
server-info.c
+1
-1
@@ -296,7 +296,7 @@ static void init_pack_info(const char *infofile, int force)
296
297
i = num_pack++;
298
ALLOC_GROW(info, num_pack, alloc);
299
- info[i] = xcalloc(1, sizeof(struct pack_info));
299
+ CALLOC_ARRAY(info[i], 1);
300
info[i]->p = p;
301
info[i]->old_num = -1;
302
}
split-index.c
+2
-2
@@ -5,7 +5,7 @@
5
struct split_index *init_split_index(struct index_state *istate)
6
{
7
if (!istate->split_index) {
8
- istate->split_index = xcalloc(1, sizeof(*istate->split_index));
8
+ CALLOC_ARRAY(istate->split_index, 1);
9
istate->split_index->refcount = 1;
10
}
11
return istate->split_index;
@@ -87,7 +87,7 @@ void move_cache_to_base_index(struct index_state *istate)
87
mem_pool_combine(istate->ce_mem_pool, istate->split_index->base->ce_mem_pool);
88
}
89
90
- si->base = xcalloc(1, sizeof(*si->base));
90
+ CALLOC_ARRAY(si->base, 1);
91
si->base->version = istate->version;
92
/* zero timestamp disables racy test in ce_write_index() */
93
si->base->timestamp = istate->timestamp;
trailer.c
+1
-1
@@ -445,7 +445,7 @@ static struct arg_item *get_conf_item(const char *name)
445
}
446
447
/* Item does not already exists, create it */
448
- item = xcalloc(sizeof(*item), 1);
448
+ CALLOC_ARRAY(item, 1);
449
duplicate_conf(&item->conf, &default_conf_info);
450
item->conf.name = xstrdup(name);
451
transport-helper.c
+2
-2
@@ -745,13 +745,13 @@ static int push_update_ref_status(struct strbuf *buf,
745
die(_("'option' without a matching 'ok/error' directive"));
746
if (state->new_report) {
747
if (!state->hint->report) {
748
- state->hint->report = xcalloc(1, sizeof(struct ref_push_report));
748
+ CALLOC_ARRAY(state->hint->report, 1);
749
state->report = state->hint->report;
750
} else {
751
state->report = state->hint->report;
752
while (state->report->next)
753
state->report = state->report->next;
754
- state->report->next = xcalloc(1, sizeof(struct ref_push_report));
754
+ CALLOC_ARRAY(state->report->next, 1);
755
state->report = state->report->next;
756
}
757
state->new_report = 0;
transport.c
+1
-1
@@ -871,7 +871,7 @@ void transport_take_over(struct transport *transport,
871
BUG("taking over transport requires non-NULL "
872
"smart_options field.");
873
874
- data = xcalloc(1, sizeof(*data));
874
+ CALLOC_ARRAY(data, 1);
875
data->options = *transport->smart_options;
876
data->conn = child;
877
data->fd[0] = data->conn->out;
worktree.c
+2
-2
@@ -53,7 +53,7 @@ static struct worktree *get_main_worktree(void)
53
strbuf_add_real_path(&worktree_path, get_git_common_dir());
54
strbuf_strip_suffix(&worktree_path, "/.git");
55
56
- worktree = xcalloc(1, sizeof(*worktree));
56
+ CALLOC_ARRAY(worktree, 1);
57
worktree->path = strbuf_detach(&worktree_path, NULL);
58
/*
59
* NEEDSWORK: If this function is called from a secondary worktree and
@@ -84,7 +84,7 @@ static struct worktree *get_linked_worktree(const char *id)
84
strbuf_rtrim(&worktree_path);
85
strbuf_strip_suffix(&worktree_path, "/.git");
86
87
- worktree = xcalloc(1, sizeof(*worktree));
87
+ CALLOC_ARRAY(worktree, 1);
88
worktree->path = strbuf_detach(&worktree_path, NULL);
89
worktree->id = xstrdup(id);
90
add_head_info(worktree);
wt-status.c
+3
-3
@@ -456,7 +456,7 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
456
it = string_list_insert(&s->change, p->two->path);
457
d = it->util;
458
if (!d) {
459
- d = xcalloc(1, sizeof(*d));
459
+ CALLOC_ARRAY(d, 1);
460
it->util = d;
461
}
462
if (!d->worktree_status)
@@ -540,7 +540,7 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
540
it = string_list_insert(&s->change, p->two->path);
541
d = it->util;
542
if (!d) {
543
- d = xcalloc(1, sizeof(*d));
543
+ CALLOC_ARRAY(d, 1);
544
it->util = d;
545
}
546
if (!d->index_status)
@@ -671,7 +671,7 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
671
it = string_list_insert(&s->change, ce->name);
672
d = it->util;
673
if (!d) {
674
- d = xcalloc(1, sizeof(*d));
674
+ CALLOC_ARRAY(d, 1);
675
it->util = d;
676
}
677
if (ce_stage(ce)) {