Skip to content

Commit e693ccf

Browse files
pks-tttaylorr
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 31eedd1 commit e693ccf

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

reftable/stack.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -623,14 +623,14 @@ int reftable_stack_add(struct reftable_stack *st,
623623
return 0;
624624
}
625625

626-
static void format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
626+
static int format_name(struct reftable_buf *dest, uint64_t min, uint64_t max)
627627
{
628628
char buf[100];
629629
uint32_t rnd = (uint32_t)git_rand();
630630
snprintf(buf, sizeof(buf), "0x%012" PRIx64 "-0x%012" PRIx64 "-%08x",
631631
min, max, rnd);
632632
reftable_buf_reset(dest);
633-
reftable_buf_addstr(dest, buf);
633+
return reftable_buf_addstr(dest, buf);
634634
}
635635

636636
struct reftable_addition {
@@ -846,7 +846,10 @@ int reftable_addition_add(struct reftable_addition *add,
846846
int tab_fd;
847847

848848
reftable_buf_reset(&next_name);
849-
format_name(&next_name, add->next_update_index, add->next_update_index);
849+
850+
err = format_name(&next_name, add->next_update_index, add->next_update_index);
851+
if (err < 0)
852+
goto done;
850853

851854
stack_filename(&temp_tab_file_name, add->stack, next_name.buf);
852855
reftable_buf_addstr(&temp_tab_file_name, ".temp.XXXXXX");
@@ -893,7 +896,9 @@ int reftable_addition_add(struct reftable_addition *add,
893896
goto done;
894897
}
895898

896-
format_name(&next_name, wr->min_update_index, wr->max_update_index);
899+
err = format_name(&next_name, wr->min_update_index, wr->max_update_index);
900+
if (err < 0)
901+
goto done;
897902
reftable_buf_addstr(&next_name, ".ref");
898903
stack_filename(&tab_file_name, add->stack, next_name.buf);
899904

@@ -944,9 +949,11 @@ static int stack_compact_locked(struct reftable_stack *st,
944949
struct tempfile *tab_file;
945950
int tab_fd, err = 0;
946951

947-
format_name(&next_name,
948-
reftable_reader_min_update_index(st->readers[first]),
949-
reftable_reader_max_update_index(st->readers[last]));
952+
err = format_name(&next_name, reftable_reader_min_update_index(st->readers[first]),
953+
reftable_reader_max_update_index(st->readers[last]));
954+
if (err < 0)
955+
goto done;
956+
950957
stack_filename(&tab_file_path, st, next_name.buf);
951958
reftable_buf_addstr(&tab_file_path, ".temp.XXXXXX");
952959

@@ -1370,8 +1377,11 @@ static int stack_compact_range(struct reftable_stack *st,
13701377
* it into place now.
13711378
*/
13721379
if (!is_empty_table) {
1373-
format_name(&new_table_name, st->readers[first]->min_update_index,
1374-
st->readers[last]->max_update_index);
1380+
err = format_name(&new_table_name, st->readers[first]->min_update_index,
1381+
st->readers[last]->max_update_index);
1382+
if (err < 0)
1383+
goto done;
1384+
13751385
reftable_buf_addstr(&new_table_name, ".ref");
13761386
stack_filename(&new_table_path, st, new_table_name.buf);
13771387

0 commit comments

Comments
 (0)