summaryrefslogtreecommitdiffstats
path: root/xdiff/xhistogram.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-07-08 18:25:18 +0200
committerJunio C Hamano <gitster@pobox.com>2022-07-08 18:34:30 +0200
commit848fd5ae5b6506df50ae872302d94b794dc57d51 (patch)
treee826df62795df5dd9b55b1f4aa0c38005e7a2294 /xdiff/xhistogram.c
parentxdiff: introduce xdl_calloc (diff)
downloadgit-848fd5ae5b6506df50ae872302d94b794dc57d51.tar.xz
git-848fd5ae5b6506df50ae872302d94b794dc57d51.zip
xdiff: introduce XDL_CALLOC_ARRAY()
Add a helper for allocating an array and initialize the elements to zero. This is analogous to CALLOC_ARRAY() in the rest of the codebase but it returns NULL on allocation failures rather than dying to accommodate other users of libxdiff such as libgit2. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xhistogram.c')
-rw-r--r--xdiff/xhistogram.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
index c97edc1e29..df909004c1 100644
--- a/xdiff/xhistogram.c
+++ b/xdiff/xhistogram.c
@@ -266,17 +266,14 @@ static int find_lcs(xpparam_t const *xpp, xdfenv_t *env,
index.table_bits = xdl_hashbits(count1);
index.records_size = 1 << index.table_bits;
- if (!(index.records = xdl_calloc(index.records_size,
- sizeof(*index.records))))
+ if (!XDL_CALLOC_ARRAY(index.records, index.records_size))
goto cleanup;
index.line_map_size = count1;
- if (!(index.line_map = xdl_calloc(index.line_map_size,
- sizeof(*index.line_map))))
+ if (!XDL_CALLOC_ARRAY(index.line_map, index.line_map_size))
goto cleanup;
- if (!(index.next_ptrs = xdl_calloc(index.line_map_size,
- sizeof(*index.next_ptrs))))
+ if (!XDL_CALLOC_ARRAY(index.next_ptrs, index.line_map_size))
goto cleanup;
/* lines / 4 + 1 comes from xprepare.c:xdl_prepare_ctx() */