Skip to content

Commit 445f9f4

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6f6127d commit 445f9f4

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

reftable/iter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
146146
static int indexed_table_ref_iter_seek(void *p UNUSED,
147147
struct reftable_record *want UNUSED)
148148
{
149-
BUG("seeking indexed table is not supported");
150-
return -1;
149+
return REFTABLE_API_ERROR;
151150
}
152151

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

reftable/reader.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,17 +677,13 @@ int reftable_reader_new(struct reftable_reader **out,
677677

678678
void reftable_reader_incref(struct reftable_reader *r)
679679
{
680-
if (!r->refcount)
681-
BUG("cannot increment ref counter of dead reader");
682680
r->refcount++;
683681
}
684682

685683
void reftable_reader_decref(struct reftable_reader *r)
686684
{
687685
if (!r)
688686
return;
689-
if (!r->refcount)
690-
BUG("cannot decrement ref counter of dead reader");
691687
if (--r->refcount)
692688
return;
693689
block_source_close(&r->source);

reftable/writer.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int reftable_writer_new(struct reftable_writer **out,
158158
opts = *_opts;
159159
options_set_defaults(&opts);
160160
if (opts.block_size >= (1 << 24))
161-
BUG("configured block size exceeds 16MB");
161+
return REFTABLE_API_ERROR;
162162

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

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

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

0 commit comments

Comments
 (0)