reftable/block: handle allocation failures

Handle allocation failures in `block_writer_init()` and
`block_reader_init()`. This requires us to bubble up error codes into
`writer_reinit_block_writer()`. Adapt call sites accordingly.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-10-02 12:56:19 +02:00
committed by Junio C Hamano
parent cd6a47167e
commit 2d5dbb37b2
4 changed files with 69 additions and 29 deletions

View File

@ -34,8 +34,9 @@ static void t_ref_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
block.len = block_size;
block_source_from_strbuf(&block.source ,&buf);
block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
rec.u.ref.refname = (char *) "";
rec.u.ref.value_type = REFTABLE_REF_DELETION;
@ -126,8 +127,9 @@ static void t_log_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
block.len = block_size;
block_source_from_strbuf(&block.source ,&buf);
block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
ret = block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
for (i = 0; i < N; i++) {
rec.u.log.refname = xstrfmt("branch%02"PRIuMAX , (uintmax_t)i);
@ -214,8 +216,9 @@ static void t_obj_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
block.len = block_size;
block_source_from_strbuf(&block.source, &buf);
block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
for (i = 0; i < N; i++) {
uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated;
@ -296,8 +299,9 @@ static void t_index_block_read_write(void)
REFTABLE_CALLOC_ARRAY(block.data, block_size);
block.len = block_size;
block_source_from_strbuf(&block.source, &buf);
block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
header_off, hash_size(GIT_SHA1_FORMAT_ID));
check(!ret);
for (i = 0; i < N; i++) {
strbuf_init(&recs[i].u.idx.last_key, 9);