Subject: Re: [PATCH] fix -Wmaybe-uninitialized with -Og

From: Junio C Hamano <[email-masked]>
Date: Mon, 04 Aug 2025 06:46:50 -0700

Jeff King <[email-masked]> 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.