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

Re: [PATCH v2] diff: ensure correct lifetime of external_diff_cmd

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 12, 2019, 02:44 UTC
Message-ID
<xmqq1s5iy4qy.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190111202608.10576-1-kgybels@infogroep.be>
Kim Gybels <kgybels@infogroep.be> writes:
Show 9 quoted lines
> According to getenv(3)'s notes:
>
>     The implementation of getenv() is not required to be reentrant.  The
>     string pointed to by the return value of getenv() may be statically
>     allocated, and can be modified by a subsequent call to getenv(),
>     putenv(3), setenv(3), or unsetenv(3).
> ...
> Signed-off-by: Kim Gybels <kgybels@infogroep.be>
> ---
Thanks, looking good.
Will queue.
Show 23 quoted lines
>
> Uses xstrdup_or_null as suggested by Eric Sunshine.
>
>  diff.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/diff.c b/diff.c
> index dc9965e836..5634992bbc 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -487,11 +487,11 @@ static const char *external_diff(void)
>  	static const char *external_diff_cmd = NULL;
>  	static int done_preparing = 0;
>  
>  	if (done_preparing)
>  		return external_diff_cmd;
> -	external_diff_cmd = getenv("GIT_EXTERNAL_DIFF");
> +	external_diff_cmd = xstrdup_or_null(getenv("GIT_EXTERNAL_DIFF"));
>  	if (!external_diff_cmd)
>  		external_diff_cmd = external_diff_cmd_cfg;
>  	done_preparing = 1;
>  	return external_diff_cmd;
>  }
Previous: Kim Gybels
Message 6 of 6 in “diff: ensure correct lifetime of external_diff_cmd”
  1. diff: ensure correct lifetime of external_diff_cmdKim Gybels, Jan 9, 2019
  2. Eric SunshineJan 9, 2019
  3. Johannes SchindelinJan 10, 2019
  4. Junio C HamanoJan 10, 2019
  5. diff: ensure correct lifetime of external_diff_cmdKim Gybels, Jan 11, 2019
  6. Junio C HamanoJan 12, 2019

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.