git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix -Wmaybe-uninitialized with -Og
@ 2025-08-04 10:07 Denton Liu
  2025-08-04 13:19 ` Jeff King
  2025-08-05  5:31 ` [PATCH v2 0/2] " Denton Liu
  0 siblings, 2 replies; 10+ messages in thread
From: Denton Liu @ 2025-08-04 10:07 UTC (permalink / raw)
  To: Git Mailing List

When building with -Og on gcc 15.1.1, the build produces two warnings.
Even though in practice, these codepaths can't actually be hit while the
variables are uninitialized, satisfy the compiler by initializing the
variables.

This also acts as defensive programming since these codepaths are a
little bit spaghetti. If someone in the future makes a mistake and
causes the branch with the uninitialized variable to be hit, at least we
won't experience undefined behaviour.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/remote.c         | 2 +-
 t/unit-tests/clar/clar.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index 5dd6cbbaee..cc462677e1 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1463,7 +1463,7 @@ static int set_head(int argc, const char **argv, const char *prefix,
 		b_local_head = STRBUF_INIT;
 	char *head_name = NULL;
 	struct ref_store *refs = get_main_ref_store(the_repository);
-	struct remote *remote;
+	struct remote *remote = NULL;
 
 	struct option options[] = {
 		OPT_BOOL('a', "auto", &opt_a,
diff --git a/t/unit-tests/clar/clar.c b/t/unit-tests/clar/clar.c
index d54e455367..03a3aa8e87 100644
--- a/t/unit-tests/clar/clar.c
+++ b/t/unit-tests/clar/clar.c
@@ -350,7 +350,7 @@ static void
 clar_run_suite(const struct clar_suite *suite, const char *filter)
 {
 	const struct clar_func *test = suite->tests;
-	size_t i, matchlen;
+	size_t i, matchlen = 0;
 	struct clar_report *report;
 	int exact = 0;
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-08-11  9:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04 10:07 [PATCH] fix -Wmaybe-uninitialized with -Og Denton Liu
2025-08-04 13:19 ` Jeff King
2025-08-04 13:46   ` Junio C Hamano
2025-08-04 15:53     ` Jeff King
2025-08-05  5:31 ` [PATCH v2 0/2] " Denton Liu
2025-08-05  5:31   ` [PATCH v2 1/2] remote: bail early from set_head() if missing remote name Denton Liu
2025-08-05  5:31   ` [PATCH v2 2/2] t/unit-tests/clar: fix -Wmaybe-uninitialized with -Og Denton Liu
2025-08-08  5:48     ` Patrick Steinhardt
2025-08-08  7:55       ` Denton Liu
2025-08-11  9:00         ` Patrick Steinhardt

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).