diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-02-06 07:35:27 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2024-02-06 12:10:08 -0800 |
| commit | b4ff12c8eefff9cba73ba3cb7492111adfa31d87 (patch) | |
| tree | cf75adb950d3c8bc7fd2743513ead645a5dbe453 /reftable/block.c | |
| parent | f6b58c1be40ba4bd6e7f2364acfe5fa34ce04120 (diff) | |
| download | git-b4ff12c8eefff9cba73ba3cb7492111adfa31d87.tar.xz | |
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/block.c')
| -rw-r--r-- | reftable/block.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/reftable/block.c b/reftable/block.c index 6952d0facf..838759823a 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -143,8 +143,10 @@ int block_writer_finish(struct block_writer *w) int block_header_skip = 4 + w->header_off; uLongf src_len = w->next - block_header_skip; uLongf dest_cap = src_len * 1.001 + 12; + uint8_t *compressed; + + REFTABLE_ALLOC_ARRAY(compressed, dest_cap); - uint8_t *compressed = reftable_malloc(dest_cap); while (1) { uLongf out_dest_len = dest_cap; int zresult = compress2(compressed, &out_dest_len, @@ -201,9 +203,9 @@ int block_reader_init(struct block_reader *br, struct reftable_block *block, uLongf dst_len = sz - block_header_skip; /* total size of dest buffer. */ uLongf src_len = block->len - block_header_skip; - /* Log blocks specify the *uncompressed* size in their header. - */ - uncompressed = reftable_malloc(sz); + + /* Log blocks specify the *uncompressed* size in their header. */ + REFTABLE_ALLOC_ARRAY(uncompressed, sz); /* Copy over the block header verbatim. It's not compressed. */ memcpy(uncompressed, block->data, block_header_skip); |
