diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2022-07-08 19:25:16 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-08 19:34:30 +0300 |
commit | abf04bdaa845a6650d1f44b9f5914df442559d75 (patch) | |
tree | c221dbd6f3fcac8d81ed84c96a3e6bc74ade434a /xdiff/xpatience.c | |
parent | e4a4b31577c7419497ac30cebe30d755b97752c5 (diff) |
xdiff: introduce XDL_ALLOC_ARRAY()
Add a helper to allocate an array that automatically calculates the
allocation size. This is analogous to ALLOC_ARRAY() in the rest of the
codebase but returns NULL if the allocation fails to accommodate other
users of libxdiff such as libgit2. The helper will also return NULL if
the multiplication in the allocation calculation overflows.
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xpatience.c')
-rw-r--r-- | xdiff/xpatience.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index 1a21c6a74b..ce87b9084c 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -200,7 +200,7 @@ static int binary_search(struct entry **sequence, int longest, */ static int find_longest_common_sequence(struct hashmap *map, struct entry **res) { - struct entry **sequence = xdl_malloc(map->nr * sizeof(struct entry *)); + struct entry **sequence; int longest = 0, i; struct entry *entry; @@ -211,7 +211,7 @@ static int find_longest_common_sequence(struct hashmap *map, struct entry **res) */ int anchor_i = -1; - if (!sequence) + if (!XDL_ALLOC_ARRAY(sequence, map->nr)) return -1; for (entry = map->first; entry; entry = entry->next) { |