@matheusbsbs / matheus-bagliano / commits / 1d679de58e
Fork 0

make_absolute_path: return the input path if it points to our buffer

Some codepaths call make_absolute_path with its own return value as input. In such a cases, return the path immediately. This fixes a valgrind-discovered error, whereby we tried to copy a string onto itself. Signed-off-by: Carlos Martín Nieto <cmn@elego.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Carlos Martín Nieto committed Mar 16, 2011 at 17:06 UTC 1d679de58e886e134c5569c542667a08f0faedd6
1 file changed +4
abspath.c
+4
@@ -24,6 +24,10 @@ const char *make_absolute_path(const char *path)
24 char *last_elem = NULL;
25 struct stat st;
26
27 + /* We've already done it */
28 + if (path == buf || path == next_buf)
29 + return path;
30 +
31 if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
32 die ("Too long path: %.*s", 60, path);
33