@matheusbsbs / matheus-bagliano / commits / ed0cb46ebb
Fork 0

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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Feb 14, 2010 at 22:44 UTC ed0cb46ebb020234da94a843ca341dde8e9e3911
1 file changed +3 -2
abspath.c
+3 -2
@@ -54,8 +54,9 @@ const char *make_absolute_path(const char *path)
54 if (len + strlen(last_elem) + 2 > PATH_MAX)
55 die ("Too long path name: '%s/%s'",
56 buf, last_elem);
57 - buf[len] = '/';
58 - strcpy(buf + len + 1, last_elem);
57 + if (len && buf[len-1] != '/')
58 + buf[len++] = '/';
59 + strcpy(buf + len, last_elem);
60 free(last_elem);
61 last_elem = NULL;
62 }