Skip to content

Commit 2756ca4

Browse files
rscharfegitster
authored andcommitted
use REALLOC_ARRAY for changing the allocation size of arrays
Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3ac22f8 commit 2756ca4

26 files changed

+40
-70
lines changed

attr.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ static struct git_attr *git_attr_internal(const char *name, int len)
9797
a->attr_nr = attr_nr++;
9898
git_attr_hash[pos] = a;
9999

100-
check_all_attr = xrealloc(check_all_attr,
101-
sizeof(*check_all_attr) * attr_nr);
100+
REALLOC_ARRAY(check_all_attr, attr_nr);
102101
check_all_attr[a->attr_nr].attr = a;
103102
check_all_attr[a->attr_nr].value = ATTR__UNKNOWN;
104103
return a;

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2626,7 +2626,7 @@ static void update_image(struct image *img,
26262626
* NOTE: this knows that we never call remove_first_line()
26272627
* on anything other than pre/post image.
26282628
*/
2629-
img->line = xrealloc(img->line, nr * sizeof(*img->line));
2629+
REALLOC_ARRAY(img->line, nr);
26302630
img->line_allocated = img->line;
26312631
}
26322632
if (preimage_limit != postimage->nr)

builtin/for-each-ref.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ static int parse_atom(const char *atom, const char *ep)
138138
/* Add it in, including the deref prefix */
139139
at = used_atom_cnt;
140140
used_atom_cnt++;
141-
used_atom = xrealloc(used_atom,
142-
(sizeof *used_atom) * used_atom_cnt);
143-
used_atom_type = xrealloc(used_atom_type,
144-
(sizeof(*used_atom_type) * used_atom_cnt));
141+
REALLOC_ARRAY(used_atom, used_atom_cnt);
142+
REALLOC_ARRAY(used_atom_type, used_atom_cnt);
145143
used_atom[at] = xmemdupz(atom, ep - atom);
146144
used_atom_type[at] = valid_atom[i].cmp_type;
147145
if (*atom == '*')
@@ -870,8 +868,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f
870868
ref->flag = flag;
871869

872870
cnt = cb->grab_cnt;
873-
cb->grab_array = xrealloc(cb->grab_array,
874-
sizeof(*cb->grab_array) * (cnt + 1));
871+
REALLOC_ARRAY(cb->grab_array, cnt + 1);
875872
cb->grab_array[cnt++] = ref;
876873
cb->grab_cnt = cnt;
877874
return 0;

builtin/index-pack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
11401140
int nr_objects_initial = nr_objects;
11411141
if (nr_unresolved <= 0)
11421142
die(_("confusion beyond insanity"));
1143-
objects = xrealloc(objects,
1144-
(nr_objects + nr_unresolved + 1)
1145-
* sizeof(*objects));
1143+
REALLOC_ARRAY(objects, nr_objects + nr_unresolved + 1);
11461144
memset(objects + nr_objects + 1, 0,
11471145
nr_unresolved * sizeof(*objects));
11481146
f = sha1fd(output_fd, curr_pack);

builtin/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
14401440
continue;
14411441

14421442
nr++;
1443-
list = xrealloc(list, nr * sizeof(list[0]));
1443+
REALLOC_ARRAY(list, nr);
14441444
list[nr - 1] = commit;
14451445
}
14461446
if (nr == 0)

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ static void parse_branch_merge_options(char *bmo)
556556
if (argc < 0)
557557
die(_("Bad branch.%s.mergeoptions string: %s"), branch,
558558
split_cmdline_strerror(argc));
559-
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
559+
REALLOC_ARRAY(argv, argc + 2);
560560
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
561561
argc++;
562562
argv[0] = "branch.*.mergeoptions";

builtin/mv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
184184

185185
modes[i] = WORKING_DIRECTORY;
186186
n = argc + last - first;
187-
source = xrealloc(source, n * sizeof(char *));
188-
destination = xrealloc(destination, n * sizeof(char *));
189-
modes = xrealloc(modes, n * sizeof(enum update_mode));
190-
submodule_gitfile = xrealloc(submodule_gitfile, n * sizeof(char *));
187+
REALLOC_ARRAY(source, n);
188+
REALLOC_ARRAY(destination, n);
189+
REALLOC_ARRAY(modes, n);
190+
REALLOC_ARRAY(submodule_gitfile, n);
191191

192192
dst = add_slash(dst);
193193
dst_len = strlen(dst);

builtin/pack-objects.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ static void index_commit_for_bitmap(struct commit *commit)
8989
{
9090
if (indexed_commits_nr >= indexed_commits_alloc) {
9191
indexed_commits_alloc = (indexed_commits_alloc + 32) * 2;
92-
indexed_commits = xrealloc(indexed_commits,
93-
indexed_commits_alloc * sizeof(struct commit *));
92+
REALLOC_ARRAY(indexed_commits, indexed_commits_alloc);
9493
}
9594

9695
indexed_commits[indexed_commits_nr++] = commit;

builtin/show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
563563
default_arg[default_num++] = "show-branch";
564564
} else if (default_alloc <= default_num + 1) {
565565
default_alloc = default_alloc * 3 / 2 + 20;
566-
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
566+
REALLOC_ARRAY(default_arg, default_alloc);
567567
}
568568
default_arg[default_num++] = xstrdup(value);
569569
default_arg[default_num] = NULL;

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ extern int daemonize(void);
482482
alloc = (nr); \
483483
else \
484484
alloc = alloc_nr(alloc); \
485-
x = xrealloc((x), alloc * sizeof(*(x))); \
485+
REALLOC_ARRAY(x, alloc); \
486486
} \
487487
} while (0)
488488

0 commit comments

Comments
 (0)