aboutsummaryrefslogtreecommitdiffstats
path: root/reftable/merged.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-02-06 07:35:27 +0100
committerJunio C Hamano <gitster@pobox.com>2024-02-06 12:10:08 -0800
commitb4ff12c8eefff9cba73ba3cb7492111adfa31d87 (patch)
treecf75adb950d3c8bc7fd2743513ead645a5dbe453 /reftable/merged.c
parentf6b58c1be40ba4bd6e7f2364acfe5fa34ce04120 (diff)
downloadgit-b4ff12c8eefff9cba73ba3cb7492111adfa31d87.tar.gz
reftable: introduce macros to allocate arrays
Similar to the preceding commit, let's carry over macros to allocate arrays with `REFTABLE_ALLOC_ARRAY()` and `REFTABLE_CALLOC_ARRAY()`. This requires us to change the signature of `reftable_calloc()`, which only takes a single argument right now and thus puts the burden on the caller to calculate the final array's size. This is a net improvement though as it means that we can now provide proper overflow checks when multiplying the array size with the member size. Convert callsites of `reftable_calloc()` to the new signature and start using the new macros where possible. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable/merged.c')
-rw-r--r--reftable/merged.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/reftable/merged.c b/reftable/merged.c
index c258ce953e..2031fd51b4 100644
--- a/reftable/merged.c
+++ b/reftable/merged.c
@@ -190,7 +190,7 @@ int reftable_new_merged_table(struct reftable_merged_table **dest,
}
}
- m = reftable_calloc(sizeof(struct reftable_merged_table));
+ REFTABLE_CALLOC_ARRAY(m, 1);
m->stack = stack;
m->stack_len = n;
m->min = first_min;
@@ -240,7 +240,7 @@ static int merged_table_seek_record(struct reftable_merged_table *mt,
struct reftable_record *rec)
{
struct reftable_iterator *iters = reftable_calloc(
- sizeof(struct reftable_iterator) * mt->stack_len);
+ mt->stack_len, sizeof(*iters));
struct merged_iter merged = {
.stack = iters,
.typ = reftable_record_type(rec),