From 4d3ab44d26c47d100cec39d0ef9ed9746eb7e454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Mon, 28 Jul 2014 20:31:57 +0200 Subject: use xgetcwd() to set $GIT_DIR Instead of dying of a segmentation fault if getcwd() returns NULL, use xgetcwd() to make sure to write a useful error message and then exit in an orderly fashion. Suggested-by: Jeff King Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- git.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'git.c') diff --git a/git.c b/git.c index 9efd1a3ec1..c4e8c5cfdf 100644 --- a/git.c +++ b/git.c @@ -125,9 +125,10 @@ static int handle_options(const char ***argv, int *argc, int *envchanged) if (envchanged) *envchanged = 1; } else if (!strcmp(cmd, "--bare")) { - static char git_dir[PATH_MAX+1]; + char *cwd = xgetcwd(); is_bare_repository_cfg = 1; - setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0); + setenv(GIT_DIR_ENVIRONMENT, cwd, 0); + free(cwd); setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1); if (envchanged) *envchanged = 1; -- cgit v1.2.1