From 490544b1282416a033dc25481db205248ac0bfc8 Mon Sep 17 00:00:00 2001 From: Clemens Buchacher Date: Sat, 22 May 2010 13:13:05 +0200 Subject: get_cwd_relative(): do not misinterpret suffix as subdirectory If the current working directory is the same as the work tree path plus a suffix, e.g. 'work' and 'work-xyz', then the suffix '-xyz' would be interpreted as a subdirectory of 'work'. Signed-off-by: Clemens Buchacher Signed-off-by: Junio C Hamano --- dir.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index cb83332a26..5615f33af1 100644 --- a/dir.c +++ b/dir.c @@ -958,9 +958,14 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) } if (*dir) return NULL; - if (*cwd == '/') + switch (*cwd) { + case '\0': + return cwd; + case '/': return cwd + 1; - return cwd; + default: + return NULL; + } } int is_inside_dir(const char *dir) -- cgit v1.3