diff options
author | Junio C Hamano <junkio@cox.net> | 2005-12-26 12:34:56 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2005-12-26 17:23:59 -0800 |
commit | 7e4a2a848377241b8fb4f624d1151bbf2f8d5814 (patch) | |
tree | 5b7f555c6aebd9c32b97dc27f3a18723549415f3 /read-tree.c | |
parent | 7d6fb370bc98e5d4723103dda0829b00c79da213 (diff) | |
download | git-7e4a2a848377241b8fb4f624d1151bbf2f8d5814.tar.gz |
avoid asking ?alloc() for zero bytes.
Avoid asking for zero bytes when that change simplifies overall
logic. Later we would change the wrapper to ask for 1 byte on
platforms that return NULL for zero byte request.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'read-tree.c')
-rw-r--r-- | read-tree.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/read-tree.c b/read-tree.c index e3b9c0d9fa..a46c6fe2f5 100644 --- a/read-tree.c +++ b/read-tree.c @@ -294,17 +294,20 @@ static int unpack_trees(merge_fn_t fn) { int indpos = 0; unsigned len = object_list_length(trees); - struct tree_entry_list **posns = - xmalloc(len * sizeof(struct tree_entry_list *)); + struct tree_entry_list **posns; int i; struct object_list *posn = trees; merge_size = len; - for (i = 0; i < len; i++) { - posns[i] = ((struct tree *) posn->item)->entries; - posn = posn->next; + + if (len) { + posns = xmalloc(len * sizeof(struct tree_entry_list *)); + for (i = 0; i < len; i++) { + posns[i] = ((struct tree *) posn->item)->entries; + posn = posn->next; + } + if (unpack_trees_rec(posns, len, "", fn, &indpos)) + return -1; } - if (unpack_trees_rec(posns, len, "", fn, &indpos)) - return -1; if (trivial_merges_only && nontrivial_merge) die("Merge requires file-level merging"); |