]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reftable: stop using `BUG()` in trivial cases
authorPatrick Steinhardt <ps@pks.im>
Tue, 18 Feb 2025 09:20:43 +0000 (10:20 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Feb 2025 18:55:36 +0000 (10:55 -0800)
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>
reftable/iter.c
reftable/reader.c
reftable/writer.c

index 86e801ca9fbc6bc9a830f041979621ffb03dd3aa..b2ffb09c16bc4dff496a9840db5d0cef3c0165d3 100644 (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,
                                       struct reftable_record *want UNUSED)
 {
-       BUG("seeking indexed table is not supported");
-       return -1;
+       return REFTABLE_API_ERROR;
 }
 
 static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec)
index de6e6dd93220a7591b6d6e09cb9680547673d20c..36a5633eded9f3765f0dc891672fe7fe22c3fab0 100644 (file)
@@ -677,8 +677,6 @@ done:
 
 void reftable_reader_incref(struct reftable_reader *r)
 {
-       if (!r->refcount)
-               BUG("cannot increment ref counter of dead reader");
        r->refcount++;
 }
 
@@ -686,8 +684,6 @@ void reftable_reader_decref(struct reftable_reader *r)
 {
        if (!r)
                return;
-       if (!r->refcount)
-               BUG("cannot decrement ref counter of dead reader");
        if (--r->refcount)
                return;
        block_source_close(&r->source);
index f3ab1035d61d96f5234a2bbaef4f8f0341255ecb..239573ade245068a67b5bf6972bb61a07bb86e5e 100644 (file)
@@ -158,7 +158,7 @@ int reftable_writer_new(struct reftable_writer **out,
                opts = *_opts;
        options_set_defaults(&opts);
        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->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))
-               BUG("record of type %d added to writer of type %d",
-                   reftable_record_type(rec), block_writer_type(w->block_writer));
+               return REFTABLE_API_ERROR;
 
        /*
         * Try to add the record to the writer. If this succeeds then we're