]> git.ipfire.org Git - thirdparty/git.git/commitdiff
path.c: Don't discard the return value of vsnpath()
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>
Tue, 4 Sep 2012 17:27:54 +0000 (18:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 Sep 2012 20:34:46 +0000 (13:34 -0700)
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 <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
path.c

diff --git a/path.c b/path.c
index 9eb5333eed31ade98930d7c90e1cea61bc66dd22..741ae77ac15551446207a9f93e5e41c088639cb6 100644 (file)
--- a/path.c
+++ b/path.c
@@ -70,21 +70,22 @@ bad:
 
 char *git_snpath(char *buf, size_t n, const char *fmt, ...)
 {
+       char *ret;
        va_list args;
        va_start(args, fmt);
-       (void)vsnpath(buf, n, fmt, args);
+       ret = vsnpath(buf, n, fmt, args);
        va_end(args);
-       return buf;
+       return ret;
 }
 
 char *git_pathdup(const char *fmt, ...)
 {
-       char path[PATH_MAX];
+       char path[PATH_MAX], *ret;
        va_list args;
        va_start(args, fmt);
-       (void)vsnpath(path, sizeof(path), fmt, args);
+       ret = vsnpath(path, sizeof(path), fmt, args);
        va_end(args);
-       return xstrdup(path);
+       return xstrdup(ret);
 }
 
 char *mkpathdup(const char *fmt, ...)