Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-07-08 19:25:18 +0300
committerJunio C Hamano <gitster@pobox.com>2022-07-08 19:34:30 +0300
commit848fd5ae5b6506df50ae872302d94b794dc57d51 (patch)
treee826df62795df5dd9b55b1f4aa0c38005e7a2294 /xdiff/xprepare.c
parent18aae7e21e1a88c75adb38aa2555e0b1928b137d (diff)
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/xprepare.c')
-rw-r--r--xdiff/xprepare.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
index 45190e59fc..b016570c48 100644
--- a/xdiff/xprepare.c
+++ b/xdiff/xprepare.c
@@ -78,7 +78,7 @@ static int xdl_init_classifier(xdlclassifier_t *cf, long size, long flags) {
return -1;
}
- if (!(cf->rchash = xdl_calloc(cf->hsize, sizeof(*cf->rchash)))) {
+ if (!XDL_CALLOC_ARRAY(cf->rchash, cf->hsize)) {
xdl_cha_free(&cf->ncha);
return -1;
@@ -182,7 +182,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
hbits = xdl_hashbits((unsigned int) narec);
hsize = 1 << hbits;
- if (!(rhash = xdl_calloc(hsize, sizeof(*rhash))))
+ if (!XDL_CALLOC_ARRAY(rhash, hsize))
goto abort;
nrec = 0;
@@ -207,7 +207,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
}
}
- if (!(rchg = xdl_calloc((nrec + 2), sizeof(*rchg))))
+ if (!XDL_CALLOC_ARRAY(rchg, nrec + 2))
goto abort;
if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
@@ -380,10 +380,8 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
xdlclass_t *rcrec;
char *dis, *dis1, *dis2;
- if (!(dis = xdl_calloc(xdf1->nrec + xdf2->nrec + 2, sizeof(*dis)))) {
-
+ if (!XDL_CALLOC_ARRAY(dis, xdf1->nrec + xdf2->nrec + 2))
return -1;
- }
dis1 = dis;
dis2 = dis1 + xdf1->nrec + 1;