From f4c21e89d7c6b578140e90c02b40eccb51ab8428 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Fri, 7 Sep 2012 00:41:03 +0200 Subject: real_path(): properly handle nonexistent top-level paths The change has two points: 1. Do not strip off a leading slash, because that erroneously turns an absolute path into a relative path. 2. Do not remove slashes from groups of multiple slashes; instead let chdir() handle them. It could be, for example, that it wants to leave leading double-slashes alone. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- abspath.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'abspath.c') diff --git a/abspath.c b/abspath.c index 3e8325c736..05f2d79348 100644 --- a/abspath.c +++ b/abspath.c @@ -45,8 +45,8 @@ const char *real_path(const char *path) if (!is_directory(buf)) { char *last_slash = find_last_dir_sep(buf); if (last_slash) { - *last_slash = '\0'; last_elem = xstrdup(last_slash + 1); + last_slash[1] = '\0'; } else { last_elem = xstrdup(buf); *buf = '\0'; -- cgit v1.2.3