From fbbb4e19bee8c4d62f274f9e07b91c45e4df838c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 20 Nov 2010 13:50:51 +0700 Subject: [PATCH] get_cwd_relative(): do not misinterpret root path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Commit 490544b (get_cwd_relative(): do not misinterpret suffix as subdirectory) handles case where: dir = "/path/work"; cwd = "/path/work-xyz"; When it comes to the end of get_cwd_relative(), dir is at '\0' and cwd is at '-'. The rest of cwd, "-xyz", clearly cannot be the relative path from dir to cwd. However there is another case where: dir = "/"; /* or even "c:/" */ cwd = "/path/to/here"; In this special case, while *cwd == 'p', which is not a path separator, the rest of cwd, "path/to/here", can be returned as a relative path from dir to cwd. Handle this case and make t1509 pass again. Reported-by: Albert Strasheim Reported-by: Matthijs Kooijman Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- dir.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dir.c b/dir.c index 7f912c76f..ee9299db0 100644 --- a/dir.c +++ b/dir.c @@ -964,6 +964,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) case '/': return cwd + 1; default: + /* + * dir can end with a path separator when it's root + * directory. Return proper prefix in that case. + */ + if (dir[-1] == '/') + return cwd; return NULL; } } -- 2.26.2