git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] name-rev: fix an 'may be used uninitialized' error

From
Junio C Hamano <gitster@pobox.com>
Date
May 4, 2026, 01:13 UTC
Message-ID
<xmqqv7d4ou3m.fsf@gitster.g>
In-Reply-To
<e74a8fd8-0617-46a8-8bef-a454d51a99c1@ramsayjones.plus.com>
Ramsay Jones <ramsay@ramsayjones.plus.com> writes:
Show 26 quoted lines
> 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
			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?
Previous: Kristoffer HaugsbakkNext: Kristoffer Haugsbakk
Message 3 of 8 in “name-rev: fix an 'may be used uninitialized' error”
  1. name-rev: fix an 'may be used uninitialized' errorRamsay Jones, May 3, 2026
  2. Kristoffer HaugsbakkMay 3, 2026
  3. Junio C HamanoMay 4, 2026
  4. Kristoffer HaugsbakkMay 4, 2026
  5. Ramsay JonesMay 4, 2026
  6. Kristoffer HaugsbakkMay 4, 2026
  7. Ramsay JonesMay 5, 2026
  8. Kristoffer HaugsbakkMay 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.