Skip to content

Commit 6fb1d81

Browse files
pks-tgitster
authored andcommitted
reftable/stack: fix compiler warning due to missing braces
While perfectly legal, older compiler toolchains complain when zero-initializing structs that contain nested structs with `{0}`: /home/libgit2/source/deps/reftable/stack.c:862:35: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] struct reftable_addition empty = REFTABLE_ADDITION_INIT; ^~~~~~~~~~~~~~~~~~~~~~ /home/libgit2/source/deps/reftable/stack.c:707:33: note: expanded from macro 'REFTABLE_ADDITION_INIT' #define REFTABLE_ADDITION_INIT {0} ^ We had the discussion around whether or not we want to handle such bogus compiler errors in the past already [1]. Back then we basically decided that we do not care about such old-and-buggy compilers, so while we could fix the issue by using `{{0}}` instead this is not the preferred way to handle this in the Git codebase. We have an easier fix though: we can just drop the macro altogether and handle initialization of the struct in `reftable_stack_addition_init()`. Callers are expected to call this function already, so this change even simplifies the calling convention. [1]: https://lore.kernel.org/git/[email protected]/T/ Suggested-by: Carlo Arenas <[email protected]> Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ed5f5d commit 6fb1d81

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

reftable/stack.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,6 @@ struct reftable_addition {
664664
uint64_t next_update_index;
665665
};
666666

667-
#define REFTABLE_ADDITION_INIT {0}
668-
669667
static void reftable_addition_close(struct reftable_addition *add)
670668
{
671669
struct reftable_buf nm = REFTABLE_BUF_INIT;
@@ -693,6 +691,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
693691
struct reftable_buf lock_file_name = REFTABLE_BUF_INIT;
694692
int err;
695693

694+
memset(add, 0, sizeof(*add));
696695
add->stack = st;
697696

698697
err = flock_acquire(&add->tables_list_lock, st->list_file,
@@ -739,8 +738,10 @@ static int stack_try_add(struct reftable_stack *st,
739738
void *arg),
740739
void *arg)
741740
{
742-
struct reftable_addition add = REFTABLE_ADDITION_INIT;
743-
int err = reftable_stack_init_addition(&add, st, 0);
741+
struct reftable_addition add;
742+
int err;
743+
744+
err = reftable_stack_init_addition(&add, st, 0);
744745
if (err < 0)
745746
goto done;
746747

@@ -866,19 +867,18 @@ int reftable_stack_new_addition(struct reftable_addition **dest,
866867
struct reftable_stack *st,
867868
unsigned int flags)
868869
{
869-
int err = 0;
870-
struct reftable_addition empty = REFTABLE_ADDITION_INIT;
870+
int err;
871871

872872
REFTABLE_CALLOC_ARRAY(*dest, 1);
873873
if (!*dest)
874874
return REFTABLE_OUT_OF_MEMORY_ERROR;
875875

876-
**dest = empty;
877876
err = reftable_stack_init_addition(*dest, st, flags);
878877
if (err) {
879878
reftable_free(*dest);
880879
*dest = NULL;
881880
}
881+
882882
return err;
883883
}
884884

0 commit comments

Comments
 (0)