Skip to content

Commit 1d679de

Browse files
carlosmngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b406a2d commit 1d679de

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

abspath.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const char *make_absolute_path(const char *path)
2424
char *last_elem = NULL;
2525
struct stat st;
2626

27+
/* We've already done it */
28+
if (path == buf || path == next_buf)
29+
return path;
30+
2731
if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
2832
die ("Too long path: %.*s", 60, path);
2933

0 commit comments

Comments
 (0)