summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2014-07-17 19:45:43 +0700
committerJunio C Hamano <gitster@pobox.com>2014-07-17 11:04:01 -0700
commit2329158657a6f856a138dbc208e7787f684008c3 (patch)
treeac1449cae80afddc513ef56193f664be9330acdf
parentebc5da3208824e25a89672a3b91bd13629b215fe (diff)
downloadgit-nd/path-max-is-better-than-hardcoded-magic-1024.tar.gz
abspath.c: use PATH_MAX in real_path_internal()nd/path-max-is-better-than-hardcoded-magic-1024
This array 'cwd' is used to store the result from getcwd() and chdir() back. PATH_MAX is the right constant for the job. On systems with longer PATH_MAX (eg. 4096 on Linux), hard coding 1024 fails stuff, e.g. "git init". Make it static too to reduce stack usage. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--abspath.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/abspath.c b/abspath.c
index ca33558a91..c0c868fc22 100644
--- a/abspath.c
+++ b/abspath.c
@@ -41,7 +41,7 @@ static const char *real_path_internal(const char *path, int die_on_error)
* here so that we can chdir() back to it at the end of the
* function:
*/
- char cwd[1024] = "";
+ static char cwd[PATH_MAX];
int buf_index = 1;
@@ -49,6 +49,8 @@ static const char *real_path_internal(const char *path, int die_on_error)
char *last_elem = NULL;
struct stat st;
+ *cwd = '\0';
+
/* We've already done it */
if (path == buf || path == next_buf)
return path;