cocci: refactor common patterns to use xstrdup_or_null()

d64ea0f83b ("git-compat-util: add xstrdup_or_null helper",
2015-01-12) added a handy wrapper that allows us to get a duplicate
of a string or NULL if the original is NULL, but a handful of
codepath predate its introduction or just weren't aware of it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Junio C Hamano
2016-10-12 11:20:23 -07:00
parent 74eeaf7b72
commit 13092a916d
7 changed files with 17 additions and 20 deletions

3
git.c
View File

@ -35,8 +35,7 @@ static void save_env_before_alias(void)
orig_cwd = xgetcwd();
for (i = 0; i < ARRAY_SIZE(env_names); i++) {
orig_env[i] = getenv(env_names[i]);
if (orig_env[i])
orig_env[i] = xstrdup(orig_env[i]);
orig_env[i] = xstrdup_or_null(orig_env[i]);
}
}