git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	 Justin Tobler <jltobler@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	 Carlo Arenas <carenas@gmail.com>
Subject: [PATCH v3 4/8] reftable/stack: fix compiler warning due to missing braces
Date: Tue, 12 Aug 2025 11:54:18 +0200	[thread overview]
Message-ID: <20250812-pks-reftable-fixes-for-libgit2-v3-4-cf3b2267867e@pks.im> (raw)
In-Reply-To: <20250812-pks-reftable-fixes-for-libgit2-v3-0-cf3b2267867e@pks.im>

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/20220710081135.74964-1-sunshine@sunshineco.com/T/

Suggested-by: Carlo Arenas <carenas@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 reftable/stack.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/reftable/stack.c b/reftable/stack.c
index ed80710572..9db90cf4ed 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -664,8 +664,6 @@ struct reftable_addition {
 	uint64_t next_update_index;
 };
 
-#define REFTABLE_ADDITION_INIT {0}
-
 static void reftable_addition_close(struct reftable_addition *add)
 {
 	struct reftable_buf nm = REFTABLE_BUF_INIT;
@@ -693,6 +691,7 @@ static int reftable_stack_init_addition(struct reftable_addition *add,
 	struct reftable_buf lock_file_name = REFTABLE_BUF_INIT;
 	int err;
 
+	memset(add, 0, sizeof(*add));
 	add->stack = st;
 
 	err = flock_acquire(&add->tables_list_lock, st->list_file,
@@ -739,8 +738,10 @@ static int stack_try_add(struct reftable_stack *st,
 					    void *arg),
 			 void *arg)
 {
-	struct reftable_addition add = REFTABLE_ADDITION_INIT;
-	int err = reftable_stack_init_addition(&add, st, 0);
+	struct reftable_addition add;
+	int err;
+
+	err = reftable_stack_init_addition(&add, st, 0);
 	if (err < 0)
 		goto done;
 
@@ -866,19 +867,18 @@ int reftable_stack_new_addition(struct reftable_addition **dest,
 				struct reftable_stack *st,
 				unsigned int flags)
 {
-	int err = 0;
-	struct reftable_addition empty = REFTABLE_ADDITION_INIT;
+	int err;
 
 	REFTABLE_CALLOC_ARRAY(*dest, 1);
 	if (!*dest)
 		return REFTABLE_OUT_OF_MEMORY_ERROR;
 
-	**dest = empty;
 	err = reftable_stack_init_addition(*dest, st, flags);
 	if (err) {
 		reftable_free(*dest);
 		*dest = NULL;
 	}
+
 	return err;
 }
 

-- 
2.51.0.rc1.163.g2494970778.dirty


  parent reply	other threads:[~2025-08-12  9:54 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01 14:47 [PATCH 0/5] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 1/5] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 2/5] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 3/5] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-01 19:19   ` Eric Sunshine
2025-08-04  6:03     ` Patrick Steinhardt
2025-08-04 19:14       ` Junio C Hamano
2025-08-05  4:49         ` Patrick Steinhardt
2025-08-12  4:18           ` Carlo Arenas
2025-08-12  9:27             ` Patrick Steinhardt
2025-08-12 14:37               ` Junio C Hamano
2025-08-01 14:47 ` [PATCH 4/5] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-01 14:47 ` [PATCH 5/5] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-04  9:40 ` [PATCH v2 0/6] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-04  9:40   ` [PATCH v2 1/6] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-04  9:40   ` [PATCH v2 2/6] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-04  9:40   ` [PATCH v2 3/6] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-04  9:40   ` [PATCH v2 4/6] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-11 19:10     ` Justin Tobler
2025-08-04  9:40   ` [PATCH v2 5/6] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-11 19:34     ` Justin Tobler
2025-08-12  9:27       ` Patrick Steinhardt
2025-08-04  9:40   ` [PATCH v2 6/6] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-11 20:04     ` Justin Tobler
2025-08-12  9:28       ` Patrick Steinhardt
2025-08-12  9:54 ` [PATCH v3 0/8] reftable: a couple of improvements for libgit2 Patrick Steinhardt
2025-08-12  9:54   ` [PATCH v3 1/8] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-12  9:54   ` [PATCH v3 2/8] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-12  9:54   ` [PATCH v3 3/8] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-12  9:54   ` Patrick Steinhardt [this message]
2025-08-12 16:51     ` [PATCH v3 4/8] reftable/stack: fix compiler warning due to missing braces Justin Tobler
2025-08-12  9:54   ` [PATCH v3 5/8] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-12 16:59     ` Justin Tobler
2025-08-13  6:12       ` Patrick Steinhardt
2025-08-12  9:54   ` [PATCH v3 6/8] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-12  9:54   ` [PATCH v3 7/8] reftable: don't second-guess errors from flock interface Patrick Steinhardt
2025-08-12 17:05     ` Justin Tobler
2025-08-12  9:54   ` [PATCH v3 8/8] refs/reftable: always reload stacks when creating lock Patrick Steinhardt
2025-08-12 17:12     ` Justin Tobler
2025-08-12 19:00   ` [PATCH v3 0/8] reftable: a couple of improvements for libgit2 Carlo Arenas
2025-08-13  6:11     ` Patrick Steinhardt
2025-08-13 14:23       ` Junio C Hamano
2025-08-13  6:25 ` [PATCH v4 " Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 1/8] reftable/writer: fix type used for number of records Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 2/8] reftable/writer: drop Git-specific `QSORT()` macro Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 3/8] reftable/stack: reorder code to avoid forward declarations Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 4/8] reftable/stack: fix compiler warning due to missing braces Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 5/8] reftable/stack: allow passing flags to `reftable_stack_add()` Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 6/8] reftable/stack: handle outdated stacks when compacting Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 7/8] reftable: don't second-guess errors from flock interface Patrick Steinhardt
2025-08-13  6:25   ` [PATCH v4 8/8] refs/reftable: always reload stacks when creating lock Patrick Steinhardt
2025-08-13 14:38   ` [PATCH v4 0/8] reftable: a couple of improvements for libgit2 Justin Tobler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250812-pks-reftable-fixes-for-libgit2-v3-4-cf3b2267867e@pks.im \
    --to=ps@pks.im \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).