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
@ -1346,7 +1346,7 @@ static void fix_unresolved_deltas(struct sha1file *f)
|
||||
* before deltas depending on them, a good heuristic is to start
|
||||
* resolving deltas in the same order as their position in the pack.
|
||||
*/
|
||||
sorted_by_pos = xmalloc(nr_ref_deltas * sizeof(*sorted_by_pos));
|
||||
ALLOC_ARRAY(sorted_by_pos, nr_ref_deltas);
|
||||
for (i = 0; i < nr_ref_deltas; i++)
|
||||
sorted_by_pos[i] = &ref_deltas[i];
|
||||
qsort(sorted_by_pos, nr_ref_deltas, sizeof(*sorted_by_pos), delta_pos_compare);
|
||||
@ -1759,7 +1759,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
|
||||
if (show_stat)
|
||||
show_pack_info(stat_only);
|
||||
|
||||
idx_objects = xmalloc((nr_objects) * sizeof(struct pack_idx_entry *));
|
||||
ALLOC_ARRAY(idx_objects, nr_objects);
|
||||
for (i = 0; i < nr_objects; i++)
|
||||
idx_objects[i] = &objects[i].idx;
|
||||
curr_index = write_idx_file(index_name, idx_objects, nr_objects, &opts, pack_sha1);
|
||||
|
Reference in New Issue
Block a user