xdiff: introduce XDL_ALLOC_GROW()
commitf7b587bf656574103a0a2ad9c2337b0d15c0e92d
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Fri, 8 Jul 2022 16:25:19 +0000 (8 16:25 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Jul 2022 16:34:30 +0000 (8 09:34 -0700)
tree00bc34a5d6773022acd2a3a9434d50b7a9dc073a
parent848fd5ae5b6506df50ae872302d94b794dc57d51
xdiff: introduce XDL_ALLOC_GROW()

Add a helper to grow an array. This is analogous to ALLOC_GROW() in
the rest of the codebase but returns −1 on allocation failure to
accommodate other users of libxdiff such as libgit2. It will also
return a error if the multiplication overflows while calculating the
new allocation size. Note that this keeps doubling on reallocation
like the code it is replacing rather than increasing the existing size
by half like ALLOC_GROW(). It does however copy ALLOC_GROW()'s trick
of adding a small amount to the new allocation to avoid a lot of
reallocations at small sizes.

Note that xdl_alloc_grow_helper() uses long rather than size_t for
`nr` and `alloc` to match the existing code.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff/xmacros.h
xdiff/xprepare.c
xdiff/xutils.c
xdiff/xutils.h