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

Re: [PATCH] submodule.c: Squelch a "use before assignment" warning

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 20, 2009, 08:05 UTC
Message-ID
<7v8we17ha9.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1258680785-42235-1-git-send-email-davvid@gmail.com>
David Aguilar <davvid@gmail.com> writes:
> i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5493) compiler
> (and probably others) mistakenly thinks variable 'right' is used
> before assigned.  Work it around by giving it a fake initialization.

We see the same "fake initialization" of 'left' on the same line. By initializing it to NULL, you are hinting that initializing 'right' to NULL actually means something.

Show 10 quoted lines
> diff --git a/submodule.c b/submodule.c
> index 461faf0..0145a62 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -38,7 +38,7 @@ void show_submodule_summary(FILE *f, const char *path,
>  		const char *del, const char *add, const char *reset)
>  {
>  	struct rev_info rev;
> -	struct commit *commit, *left = left, *right;
> +	struct commit *commit, *left = left, *right = NULL;
Previous: David AguilarNext: David Aguilar
Message 2 of 6 in “submodule.c: Squelch a "use before assignment" warning”
  1. submodule.c: Squelch a "use before assignment" warningDavid Aguilar, Nov 20, 2009
  2. Junio C HamanoNov 20, 2009
  3. submodule.c: Squelch a "use before assignment" warningDavid Aguilar, Nov 20, 2009
  4. Christoph BartoschekNov 21, 2009
  5. Junio C HamanoNov 22, 2009
  6. Junio C HamanoNov 22, 2009

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.