summaryrefslogtreecommitdiff
path: root/xdiff/xutils.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-08-03 20:36:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-08-03 20:36:07 (GMT)
commit0f609558fc537a3e87f16e6c43eb538056878833 (patch)
treeefefd3af56c1efd9f0fcbce5aa0c9c51fb78c62e /xdiff/xutils.c
parentacbec18d8e763069f55f895d15ebb37e9162357d (diff)
parentf7b587bf656574103a0a2ad9c2337b0d15c0e92d (diff)
downloadgit-0f609558fc537a3e87f16e6c43eb538056878833.zip
git-0f609558fc537a3e87f16e6c43eb538056878833.tar.gz
git-0f609558fc537a3e87f16e6c43eb538056878833.tar.bz2
Merge branch 'pw/xdiff-alloc'
Add a level of redirection to array allocation API in xdiff part, to make it easier to share with the libgit2 project. * pw/xdiff-alloc: xdiff: introduce XDL_ALLOC_GROW() xdiff: introduce XDL_CALLOC_ARRAY() xdiff: introduce xdl_calloc xdiff: introduce XDL_ALLOC_ARRAY()
Diffstat (limited to 'xdiff/xutils.c')
-rw-r--r--xdiff/xutils.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 115b2b1..9e36f24 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -432,3 +432,20 @@ int xdl_fall_back_diff(xdfenv_t *diff_env, xpparam_t const *xpp,
return 0;
}
+
+void* xdl_alloc_grow_helper(void *p, long nr, long *alloc, size_t size)
+{
+ void *tmp = NULL;
+ size_t n = ((LONG_MAX - 16) / 2 >= *alloc) ? 2 * *alloc + 16 : LONG_MAX;
+ if (nr > n)
+ n = nr;
+ if (SIZE_MAX / size >= n)
+ tmp = xdl_realloc(p, n * size);
+ if (tmp) {
+ *alloc = n;
+ } else {
+ xdl_free(p);
+ *alloc = 0;
+ }
+ return tmp;
+}