reftable: stop using `BUG()` in trivial cases

Stop using `BUG()` in the remaining trivial cases that we still have in
the reftable library. Instead of aborting the program, we'll now bubble
up a `REFTABLE_API_ERROR` to indicate misuse of the calling conventions.

Note that in both `reftable_reader_{inc,dec}ref()` we simply stop
calling `BUG()` altogether. The only situation where the counter should
be zero is when the structure has already been free'd anyway, so we
would run into undefined behaviour regardless of whether we try to abort
the program or not.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Patrick Steinhardt 2025-02-18 10:20:43 +01:00 committed by Junio C Hamano
parent 6f6127decd
commit 445f9f4f35
3 changed files with 3 additions and 9 deletions

View File

@ -146,8 +146,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
static int indexed_table_ref_iter_seek(void *p UNUSED, static int indexed_table_ref_iter_seek(void *p UNUSED,
struct reftable_record *want UNUSED) struct reftable_record *want UNUSED)
{ {
BUG("seeking indexed table is not supported"); return REFTABLE_API_ERROR;
return -1;
} }


static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec) static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec)

View File

@ -677,8 +677,6 @@ done:


void reftable_reader_incref(struct reftable_reader *r) void reftable_reader_incref(struct reftable_reader *r)
{ {
if (!r->refcount)
BUG("cannot increment ref counter of dead reader");
r->refcount++; r->refcount++;
} }


@ -686,8 +684,6 @@ void reftable_reader_decref(struct reftable_reader *r)
{ {
if (!r) if (!r)
return; return;
if (!r->refcount)
BUG("cannot decrement ref counter of dead reader");
if (--r->refcount) if (--r->refcount)
return; return;
block_source_close(&r->source); block_source_close(&r->source);

View File

@ -158,7 +158,7 @@ int reftable_writer_new(struct reftable_writer **out,
opts = *_opts; opts = *_opts;
options_set_defaults(&opts); options_set_defaults(&opts);
if (opts.block_size >= (1 << 24)) if (opts.block_size >= (1 << 24))
BUG("configured block size exceeds 16MB"); return REFTABLE_API_ERROR;


reftable_buf_init(&wp->block_writer_data.last_key); reftable_buf_init(&wp->block_writer_data.last_key);
reftable_buf_init(&wp->last_key); reftable_buf_init(&wp->last_key);
@ -302,8 +302,7 @@ static int writer_add_record(struct reftable_writer *w,
} }


if (block_writer_type(w->block_writer) != reftable_record_type(rec)) if (block_writer_type(w->block_writer) != reftable_record_type(rec))
BUG("record of type %d added to writer of type %d", return REFTABLE_API_ERROR;
reftable_record_type(rec), block_writer_type(w->block_writer));


/* /*
* Try to add the record to the writer. If this succeeds then we're * Try to add the record to the writer. If this succeeds then we're