summaryrefslogtreecommitdiffstats
path: root/xdiff/xhistogram.c
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2022-07-08 18:25:17 +0200
committerJunio C Hamano <gitster@pobox.com>2022-07-08 18:34:30 +0200
commit18aae7e21e1a88c75adb38aa2555e0b1928b137d (patch)
tree1f48acc01e9e7b01cf8380dad5a9f4277db437b5 /xdiff/xhistogram.c
parentxdiff: introduce XDL_ALLOC_ARRAY() (diff)
downloadgit-18aae7e21e1a88c75adb38aa2555e0b1928b137d.tar.xz
git-18aae7e21e1a88c75adb38aa2555e0b1928b137d.zip
xdiff: introduce xdl_calloc
In preparation for introducing XDL_CALLOC_ARRAY() use calloc() to obtain zeroed out memory rather than malloc() followed by memset(). To try and keep the lines a reasonable length this commit also stops casting the pointer returned by calloc() as this is unnecessary. 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.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
index 01decffc33..c97edc1e29 100644
--- a/xdiff/xhistogram.c
+++ b/xdiff/xhistogram.c
@@ -251,7 +251,7 @@ static int find_lcs(xpparam_t const *xpp, xdfenv_t *env,
int line1, int count1, int line2, int count2)
{
int b_ptr;
- int sz, ret = -1;
+ int ret = -1;
struct histindex index;
memset(&index, 0, sizeof(index));
@@ -265,23 +265,19 @@ static int find_lcs(xpparam_t const *xpp, xdfenv_t *env,
index.rcha.head = NULL;
index.table_bits = xdl_hashbits(count1);
- sz = index.records_size = 1 << index.table_bits;
- sz *= sizeof(struct record *);
- if (!(index.records = (struct record **) xdl_malloc(sz)))
+ index.records_size = 1 << index.table_bits;
+ if (!(index.records = xdl_calloc(index.records_size,
+ sizeof(*index.records))))
goto cleanup;
- memset(index.records, 0, sz);
- sz = index.line_map_size = count1;
- sz *= sizeof(struct record *);
- if (!(index.line_map = (struct record **) xdl_malloc(sz)))
+ index.line_map_size = count1;
+ if (!(index.line_map = xdl_calloc(index.line_map_size,
+ sizeof(*index.line_map))))
goto cleanup;
- memset(index.line_map, 0, sz);
- sz = index.line_map_size;
- sz *= sizeof(unsigned int);
- if (!(index.next_ptrs = (unsigned int *) xdl_malloc(sz)))
+ if (!(index.next_ptrs = xdl_calloc(index.line_map_size,
+ sizeof(*index.next_ptrs))))
goto cleanup;
- memset(index.next_ptrs, 0, sz);
/* lines / 4 + 1 comes from xprepare.c:xdl_prepare_ctx() */
if (xdl_cha_init(&index.rcha, sizeof(struct record), count1 / 4 + 1) < 0)