diff options
| author | Patrick Steinhardt <ps@pks.im> | 2024-10-17 06:54:08 +0200 |
|---|---|---|
| committer | Taylor Blau <me@ttaylorr.com> | 2024-10-17 16:59:56 -0400 |
| commit | 4abc8022ffae64bb24e93153c75bc880991bb2dc (patch) | |
| tree | ba63e3e1e4a25962e13e70a79d610646da4e7120 /reftable/block.c | |
| parent | e693ccf2c9427dfd5d93db723ac68f49f550ed38 (diff) | |
| download | git-4abc8022ffae64bb24e93153c75bc880991bb2dc.tar.xz | |
reftable/record: adapt `reftable_record_key()` to handle allocation failures
The `reftable_record_key()` function cannot pass any errors to the
caller as it has a `void` return type. Adapt it and its callers such
that we can handle errors and start handling allocation failures.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'reftable/block.c')
| -rw-r--r-- | reftable/block.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/reftable/block.c b/reftable/block.c index 4f62b823db..697b8b4153 100644 --- a/reftable/block.c +++ b/reftable/block.c @@ -111,9 +111,12 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) int is_restart = 0; struct reftable_buf key = REFTABLE_BUF_INIT; int n = 0; - int err = -1; + int err; + + err = reftable_record_key(rec, &key); + if (err < 0) + goto done; - reftable_record_key(rec, &key); if (!key.len) { err = REFTABLE_API_ERROR; goto done; @@ -121,13 +124,17 @@ int block_writer_add(struct block_writer *w, struct reftable_record *rec) n = reftable_encode_key(&is_restart, out, last, key, reftable_record_val_type(rec)); - if (n < 0) + if (n < 0) { + err = -1; goto done; + } string_view_consume(&out, n); n = reftable_record_encode(rec, out, w->hash_size); - if (n < 0) + if (n < 0) { + err = -1; goto done; + } string_view_consume(&out, n); err = block_writer_register_restart(w, start.len - out.len, is_restart, @@ -522,6 +529,10 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, goto done; } + err = reftable_record_key(&rec, &it->last_key); + if (err < 0) + goto done; + /* * Check whether the current key is greater or equal to the * sought-after key. In case it is greater we know that the @@ -536,7 +547,6 @@ int block_iter_seek_key(struct block_iter *it, const struct block_reader *br, * to `last_key` now, and naturally all keys share a prefix * with themselves. */ - reftable_record_key(&rec, &it->last_key); if (reftable_buf_cmp(&it->last_key, want) >= 0) { it->next_off = prev_off; goto done; |
