aboutsummaryrefslogtreecommitdiffstats
path: root/reftable/stack.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-10-17 06:54:05 +0200
committerTaylor Blau <me@ttaylorr.com>2024-10-17 16:59:56 -0400
commite693ccf2c9427dfd5d93db723ac68f49f550ed38 (patch)
treea2d8812e7b2f02972bfc338c97a4faac14c77377 /reftable/stack.c
parent31eedd1d115c086a84aaa5b53b14294d0afda4ae (diff)
downloadgit-e693ccf2c9427dfd5d93db723ac68f49f550ed38.tar.gz
reftable/stack: adapt `format_name()` to handle allocation failures
The `format_name()` 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/stack.c')
-rw-r--r--reftable/stack.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/reftable/stack.c b/reftable/stack.c
index 6ba48ddce5..e94eb3c468 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -623,14 +623,14 @@ int reftable_stack_add(struct reftable_stack *st,
return 0;
}
-static void format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
+static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
{
char buf[100];
uint32_t rnd = (uint32_t)git_rand();
snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x",
min, max, rnd);
reftable_buf_reset(dest);
- reftable_buf_addstr(dest, buf);
+ return reftable_buf_addstr(dest, buf);
}
struct reftable_addition {
@@ -846,7 +846,10 @@ int reftable_addition_add(struct reftable_addition *add,
int tab_fd;
reftable_buf_reset(&next_name);
- format_name(&next_name, add->next_update_index, add->next_update_index);
+
+ err = format_name(&next_name, add->next_update_index, add->next_update_index);
+ if (err < 0)
+ goto done;
stack_filename(&temp_tab_file_name, add->stack, next_name.buf);
reftable_buf_addstr(&temp_tab_file_name, ".temp.XXXXXX");
@@ -893,7 +896,9 @@ int reftable_addition_add(struct reftable_addition *add,
goto done;
}
- format_name(&next_name, wr->min_update_index, wr->max_update_index);
+ err = format_name(&next_name, wr->min_update_index, wr->max_update_index);
+ if (err < 0)
+ goto done;
reftable_buf_addstr(&next_name, ".ref");
stack_filename(&tab_file_name, add->stack, next_name.buf);
@@ -944,9 +949,11 @@ static int stack_compact_locked(struct reftable_stack *st,
struct tempfile *tab_file;
int tab_fd, err = 0;
- format_name(&next_name,
- reftable_reader_min_update_index(st->readers[first]),
- reftable_reader_max_update_index(st->readers[last]));
+ err = format_name(&next_name, reftable_reader_min_update_index(st->readers[first]),
+ reftable_reader_max_update_index(st->readers[last]));
+ if (err < 0)
+ goto done;
+
stack_filename(&tab_file_path, st, next_name.buf);
reftable_buf_addstr(&tab_file_path, ".temp.XXXXXX");
@@ -1370,8 +1377,11 @@ static int stack_compact_range(struct reftable_stack *st,
* it into place now.
*/
if (!is_empty_table) {
- format_name(&new_table_name, st->readers[first]->min_update_index,
- st->readers[last]->max_update_index);
+ err = format_name(&new_table_name, st->readers[first]->min_update_index,
+ st->readers[last]->max_update_index);
+ if (err < 0)
+ goto done;
+
reftable_buf_addstr(&new_table_name, ".ref");
stack_filename(&new_table_path, st, new_table_name.buf);