git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Denton Liu <liu.denton@gmail.com>,
	 Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH] fix -Wmaybe-uninitialized with -Og
Date: Mon, 04 Aug 2025 06:46:50 -0700	[thread overview]
Message-ID: <xmqqms8f9p2t.fsf@gitster.g> (raw)
In-Reply-To: <20250804131922.GB86602@coredump.intra.peff.net> (Jeff King's message of "Mon, 4 Aug 2025 09:19:22 -0400")

Jeff King <peff@peff.net> writes:

> So I wonder if this would be much more obvious (again, to both humans
> and compilers):
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 5dd6cbbaee..f0e49a5681 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -1474,10 +1474,13 @@ static int set_head(int argc, const char **argv, const char *prefix,
>  	};
>  	argc = parse_options(argc, argv, prefix, options,
>  			     builtin_remote_sethead_usage, 0);
> -	if (argc) {
> -		strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]);
> -		remote = remote_get(argv[0]);
> -	}
> +
> +	/* All modes require at least a remote name. */
> +	if (!argc)
> +		usage_with_options(builtin_remote_sethead_usage, options);
> +
> +	strbuf_addf(&b_head, "refs/remotes/%s/HEAD", argv[0]);
> +	remote = remote_get(argv[0]);

I do not know about compilers, but a sample of one, to this human it
is more obvious ;-).

> and the line it complains about is:
>
>   if (filter && strncmp(test[i].name, filter, matchlen))
> ...
> At any rate I agree that "0" is the appropriate value here, and
> assigning it to shut up the compiler is the best approach.

... simply because we know the value in matchlen does not matter
when filter is NULL?  I think that would work and I would be happy
with a less noisy compilation.

But any other value like 99 would equally well work, which is a bit
disturbing ;-).

Thanks.

  reply	other threads:[~2025-08-04 13:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

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=xmqqms8f9p2t.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=liu.denton@gmail.com \
    --cc=peff@peff.net \
    /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).