From: Nguyễn Thái Ngọc Duy Date: Sun, 14 Feb 2010 15:44:41 +0000 (+0700) Subject: make_absolute_path(): Do not append redundant slash X-Git-Tag: v1.7.1-rc0~89^2~4 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ed0cb46ebb020234da94a843ca341dde8e9e3911;p=git.git make_absolute_path(): Do not append redundant slash When concatenating two paths, if the first one already have '/', do not put another '/' in between the two paths. Usually this is not the case as getcwd() won't return '/foo/bar/', except when you are standing at root, then it will return '/'. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/abspath.c b/abspath.c index b88122cbe..c91a29cb2 100644 --- a/abspath.c +++ b/abspath.c @@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path) if (len + strlen(last_elem) + 2 > PATH_MAX) die ("Too long path name: '%s/%s'", buf, last_elem); - buf[len] = '/'; - strcpy(buf + len + 1, last_elem); + if (len && buf[len-1] != '/') + buf[len++] = '/'; + strcpy(buf + len, last_elem); free(last_elem); last_elem = NULL; }