Skip to content

Commit 66a51a9

Browse files
Ramsay Jonesgitster
authored andcommitted
path.c: Don't discard the return value of vsnpath()
The git_snpath() and git_pathdup() functions both use the (static) function vsnpath() in their implementation. Also, they both discard the return value of vsnpath(), which has the effect of ignoring the side effect of calling cleanup_path() in the non-error return path. In order to ensure that the required cleanup happens, we use the pointer returned by vsnpath(), rather than the buffer passed into vsnpath(), to derive the return value from git_snpath() and git_pathdup(). Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b3b8fa commit 66a51a9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

path.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ static char *vsnpath(char *buf, size_t n, const char *fmt, va_list args)
7070

7171
char *git_snpath(char *buf, size_t n, const char *fmt, ...)
7272
{
73+
char *ret;
7374
va_list args;
7475
va_start(args, fmt);
75-
(void)vsnpath(buf, n, fmt, args);
76+
ret = vsnpath(buf, n, fmt, args);
7677
va_end(args);
77-
return buf;
78+
return ret;
7879
}
7980

8081
char *git_pathdup(const char *fmt, ...)
8182
{
82-
char path[PATH_MAX];
83+
char path[PATH_MAX], *ret;
8384
va_list args;
8485
va_start(args, fmt);
85-
(void)vsnpath(path, sizeof(path), fmt, args);
86+
ret = vsnpath(path, sizeof(path), fmt, args);
8687
va_end(args);
87-
return xstrdup(path);
88+
return xstrdup(ret);
8889
}
8990

9091
char *mkpathdup(const char *fmt, ...)

0 commit comments

Comments
 (0)