aboutsummaryrefslogtreecommitdiff
path: root/fast-import.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:44:25 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commitb32fa95fd8293ebfecb2b7b6c8d460579318f9fe (patch)
tree09af1e6cc980e672e7deefe4bc8f8844a25f14b2 /fast-import.c
parent850d2fec53ee188bab9e458f77906041ac7f1904 (diff)
downloadgit-b32fa95fd8293ebfecb2b7b6c8d460579318f9fe.tar.gz
git-b32fa95fd8293ebfecb2b7b6c8d460579318f9fe.tar.xz
convert trivial cases to ALLOC_ARRAY
Each of these cases can be converted to use ALLOC_ARRAY or REALLOC_ARRAY, which has two advantages: 1. It automatically checks the array-size multiplication for overflow. 2. It always uses sizeof(*array) for the element-size, so that it can never go out of sync with the declared type of the array. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fast-import.c')
-rw-r--r--fast-import.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/fast-import.c b/fast-import.c
index 3c65edb5c..36dbaa5b1 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -814,7 +814,8 @@ static struct tree_entry *new_tree_entry(void)
if (!avail_tree_entry) {
unsigned int n = tree_entry_alloc;
total_allocd += n * sizeof(struct tree_entry);
- avail_tree_entry = e = xmalloc(n * sizeof(struct tree_entry));
+ ALLOC_ARRAY(e, n);
+ avail_tree_entry = e;
while (n-- > 1) {
*((void**)e) = e + 1;
e++;
@@ -898,7 +899,7 @@ static const char *create_index(void)
struct object_entry_pool *o;
/* Build the table of object IDs. */
- idx = xmalloc(object_count * sizeof(*idx));
+ ALLOC_ARRAY(idx, object_count);
c = idx;
for (o = blocks; o; o = o->next_pool)
for (e = o->next_free; e-- != o->entries;)