diff options
author | Phillip Wood <phillip.wood@dunelm.org.uk> | 2022-07-08 18:25:16 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-07-08 18:34:30 +0200 |
commit | abf04bdaa845a6650d1f44b9f5914df442559d75 (patch) | |
tree | c221dbd6f3fcac8d81ed84c96a3e6bc74ade434a /xdiff/xdiffi.c | |
parent | Git 2.37 (diff) | |
download | git-abf04bdaa845a6650d1f44b9f5914df442559d75.tar.xz git-abf04bdaa845a6650d1f44b9f5914df442559d75.zip |
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/xdiffi.c')
-rw-r--r-- | xdiff/xdiffi.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 758410c11a..53e803e6bc 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -337,7 +337,7 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, * One is to store the forward path and one to store the backward path. */ ndiags = xe->xdf1.nreff + xe->xdf2.nreff + 3; - if (!(kvd = (long *) xdl_malloc((2 * ndiags + 2) * sizeof(long)))) { + if (!XDL_ALLOC_ARRAY(kvd, 2 * ndiags + 2)) { xdl_free_env(xe); return -1; |