reftable/reader: handle allocation failures in reader_init_iter()

Handle allocation failures in `reader_init_iter()`. This requires us to
also adapt `reftable_reader_init_*_iterator()` to bubble up the new
error codes. Adapt callers 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:55:59 +02:00
committed by Junio C Hamano
parent 18da600293
commit 0a8372f509
5 changed files with 50 additions and 30 deletions

View File

@ -206,7 +206,8 @@ static void t_log_write_read(void)
err = reftable_reader_new(&reader, &source, "file.log");
check(!err);
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, names[N - 1]);
check(!err);
@ -221,8 +222,8 @@ static void t_log_write_read(void)
reftable_iterator_destroy(&it);
reftable_ref_record_release(&ref);
reftable_reader_init_log_iterator(reader, &it);
err = reftable_reader_init_log_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_log(&it, "");
check(!err);
@ -296,7 +297,8 @@ static void t_log_zlib_corruption(void)
err = reftable_reader_new(&reader, &source, "file.log");
check(!err);
reftable_reader_init_log_iterator(reader, &it);
err = reftable_reader_init_log_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_log(&it, "refname");
check_int(err, ==, REFTABLE_ZLIB_ERROR);
@ -325,7 +327,8 @@ static void t_table_read_write_sequential(void)
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, "");
check(!err);
@ -376,7 +379,8 @@ static void t_table_read_api(void)
err = reftable_reader_new(&reader, &source, "file.ref");
check(!err);
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, names[0]);
check(!err);
@ -419,7 +423,8 @@ static void t_table_read_write_seek(int index, int hash_id)
}
for (i = 1; i < N; i++) {
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, names[i]);
check(!err);
err = reftable_iterator_next_ref(&it, &ref);
@ -435,7 +440,8 @@ static void t_table_read_write_seek(int index, int hash_id)
strbuf_addstr(&pastLast, names[N - 1]);
strbuf_addstr(&pastLast, "/");
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, pastLast.buf);
if (err == 0) {
struct reftable_ref_record ref = { 0 };
@ -534,7 +540,8 @@ static void t_table_refs_for(int indexed)
if (!indexed)
reader->obj_offsets.is_present = 0;
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, "");
check(!err);
reftable_iterator_destroy(&it);
@ -593,7 +600,8 @@ static void t_write_empty_table(void)
err = reftable_reader_new(&rd, &source, "filename");
check(!err);
reftable_reader_init_ref_iterator(rd, &it);
err = reftable_reader_init_ref_iterator(rd, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, "");
check(!err);
@ -802,7 +810,8 @@ static void t_write_multiple_indices(void)
* Seeking the log uses the log index now. In case there is any
* confusion regarding indices we would notice here.
*/
reftable_reader_init_log_iterator(reader, &it);
err = reftable_reader_init_log_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_log(&it, "");
check(!err);
@ -858,7 +867,8 @@ static void t_write_multi_level_index(void)
/*
* Seeking the last ref should work as expected.
*/
reftable_reader_init_ref_iterator(reader, &it);
err = reftable_reader_init_ref_iterator(reader, &it);
check(!err);
err = reftable_iterator_seek_ref(&it, "refs/heads/199");
check(!err);