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>
This commit is contained in:

committed by
Junio C Hamano

parent
850d2fec53
commit
b32fa95fd8
@ -1591,8 +1591,7 @@ static void prepare_shallow_update(struct command *commands,
|
||||
{
|
||||
int i, j, k, bitmap_size = (si->ref->nr + 31) / 32;
|
||||
|
||||
si->used_shallow = xmalloc(sizeof(*si->used_shallow) *
|
||||
si->shallow->nr);
|
||||
ALLOC_ARRAY(si->used_shallow, si->shallow->nr);
|
||||
assign_shallow_commits_to_refs(si, si->used_shallow, NULL);
|
||||
|
||||
si->need_reachability_test =
|
||||
@ -1658,7 +1657,7 @@ static void update_shallow_info(struct command *commands,
|
||||
return;
|
||||
}
|
||||
|
||||
ref_status = xmalloc(sizeof(*ref_status) * ref->nr);
|
||||
ALLOC_ARRAY(ref_status, ref->nr);
|
||||
assign_shallow_commits_to_refs(si, NULL, ref_status);
|
||||
for (cmd = commands; cmd; cmd = cmd->next) {
|
||||
if (is_null_sha1(cmd->new_sha1))
|
||||
|
Reference in New Issue
Block a user