summaryrefslogtreecommitdiff
path: root/pack-revindex.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 /pack-revindex.c
parent850d2fec53ee188bab9e458f77906041ac7f1904 (diff)
downloadgit-b32fa95fd8293ebfecb2b7b6c8d460579318f9fe.tar.gz
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 'pack-revindex.c')
-rw-r--r--pack-revindex.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/pack-revindex.c b/pack-revindex.c
index e542ea7703..f6a3613beb 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -83,10 +83,14 @@ static void sort_revindex(struct revindex_entry *entries, unsigned n, off_t max)
* keep track of them with alias pointers, always sorting from "from"
* to "to".
*/
- struct revindex_entry *tmp = xmalloc(n * sizeof(*tmp));
- struct revindex_entry *from = entries, *to = tmp;
+ struct revindex_entry *tmp, *from, *to;
int bits;
- unsigned *pos = xmalloc(BUCKETS * sizeof(*pos));
+ unsigned *pos;
+
+ ALLOC_ARRAY(pos, BUCKETS);
+ ALLOC_ARRAY(tmp, n);
+ from = entries;
+ to = tmp;
/*
* If (max >> bits) is zero, then we know that the radix digit we are
@@ -161,7 +165,7 @@ static void create_pack_revindex(struct pack_revindex *rix)
unsigned i;
const char *index = p->index_data;
- rix->revindex = xmalloc(sizeof(*rix->revindex) * (num_ent + 1));
+ ALLOC_ARRAY(rix->revindex, num_ent + 1);
index += 4 * 256;
if (p->index_version > 1) {