From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>,
GIT Mailing-list <git@vger.kernel.org>
Subject: Re: [PATCH] name-rev: fix an 'may be used uninitialized' error
Date: Mon, 4 May 2026 21:26:21 +0100 [thread overview]
Message-ID: <b04e98e3-0840-456d-a627-351f2378c037@ramsayjones.plus.com> (raw)
In-Reply-To: <xmqqv7d4ou3m.fsf@gitster.g>
On 04/05/2026 2:13 am, Junio C Hamano wrote:
> Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
>
>> Today's seen branch fails to build (with DEVELOPER=1), like so:
>>
>> CC builtin/name-rev.o
>> builtin/name-rev.c: In function ‘cmd_format_rev’:
>> builtin/name-rev.c:885:28: error: ‘commit’ may be used uninitialized [-Werror=maybe-uninitialized]
>> 885 | if (!commit) {
>> | ^
>> builtin/name-rev.c:867:40: note: ‘commit’ was declared here
>> 867 | struct commit *commit;
>> | ^~~~~~
>> cc1: all warnings being treated as errors
>> make: *** [Makefile:2932: builtin/name-rev.o] Error 1
>> ...
>> diff --git a/builtin/name-rev.c b/builtin/name-rev.c
>> index b941e93834..5b7f7a00e5 100644
>> --- a/builtin/name-rev.c
>> +++ b/builtin/name-rev.c
>> @@ -882,6 +882,8 @@ int cmd_format_rev(int argc,
>> peeled = deref_tag(the_repository, object, scratch_buf.buf, 0);
>> if (peeled && peeled->type == OBJ_COMMIT)
>> commit = (struct commit *)peeled;
>> + else
>> + commit = NULL;
>> if (!commit) {
>> fprintf(stderr, "Could not get commit for %s. Skipping.\n",
>> *argv);
>
> Why not
Heh, you noticed that I spent all of a few seconds writing this patch, just to get
the branch to build, as I was in a rush to go out. I wasn't quick enough anyway, so
I didn't send it until the next day. But, as I said in the patch, I wasn't pushing
this patch as _the_ fix ...
>
> if (peeled && peeled->type == OBJ_COMMIT) {
> commit = (struct commit *)peeled;
> } else {
> fprintf(stderr, "... skipping ...");
> continue;
> }
>
> get_format_rev(commit, &format_pp, &scratch);
>
> or even
>
> if (!peeled || peeled->type != OBJ_COMMIT) {
> fprintf(stderr, "... skipping ...");
> continue;
> }
>
> get_format_rev((struct commit *)peeled->type,
> &format_pp, &scratch);
>
> and dropping the variable "struct commit *commit" altogether?
Having now spent some time (well at least 30 seconds :) ) looking at the
surrounding code, then your final suggestion looks really good to me! ;)
However, these 'maybe-uninitialized' errors (historically have been) somewhat
sensitive to the level of optimization used in the compilation and even algo
used by the compiler changing frequently from one version to the next ...
So, I wasn't sure if Kristoffer was actually seeing the error or had the
DEVELOPER variable set (which is why I mentioned it in passing!).
Thanks!
ATB,
Ramsay Jones
next prev parent reply other threads:[~2026-05-04 20:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-03 15:16 [PATCH] name-rev: fix an 'may be used uninitialized' error Ramsay Jones
2026-05-03 18:52 ` Kristoffer Haugsbakk
2026-05-04 1:13 ` Junio C Hamano
2026-05-04 8:55 ` Kristoffer Haugsbakk
2026-05-04 20:26 ` Ramsay Jones [this message]
2026-05-04 21:56 ` Kristoffer Haugsbakk
2026-05-05 0:41 ` Ramsay Jones
2026-05-05 19:09 ` Kristoffer Haugsbakk
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=b04e98e3-0840-456d-a627-351f2378c037@ramsayjones.plus.com \
--to=ramsay@ramsayjones.plus.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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