Re: [PATCH v2] diff: ensure correct lifetime of external_diff_cmd
From: Junio C Hamano <hidden>
Date: 2019-01-12 02:44:10
Kim Gybels [off-list ref] writes:
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 <redacted>
---Thanks, looking good. Will queue.
quoted hunk
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; }