summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-12-20 00:05:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-20 00:05:38 (GMT)
commitea4ef304870d2517ec177f92b000c744bd44cc0c (patch)
treeb7bb736d18d8afa27292d61f9a5c18ae767a2670
parentb052781fef2f978ba9cc55d6de942bb779bd54ac (diff)
parenta9bfbc5b698103b1553e1023c4f77001cc861e79 (diff)
downloadgit-ea4ef304870d2517ec177f92b000c744bd44cc0c.zip
git-ea4ef304870d2517ec177f92b000c744bd44cc0c.tar.gz
git-ea4ef304870d2517ec177f92b000c744bd44cc0c.tar.bz2
Merge branch 'jk/maint-snprintf-va-copy'
* jk/maint-snprintf-va-copy: compat/snprintf: don't look at va_list twice
-rw-r--r--compat/snprintf.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/compat/snprintf.c b/compat/snprintf.c
index e1e0e75..42ea1ac 100644
--- a/compat/snprintf.c
+++ b/compat/snprintf.c
@@ -19,11 +19,14 @@
#undef vsnprintf
int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
{
+ va_list cp;
char *s;
int ret = -1;
if (maxsize > 0) {
- ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
+ va_copy(cp, ap);
+ ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, cp);
+ va_end(cp);
if (ret == maxsize-1)
ret = -1;
/* Windows does not NUL-terminate if result fills buffer */
@@ -42,7 +45,9 @@ int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap)
if (! str)
break;
s = str;
- ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, ap);
+ va_copy(cp, ap);
+ ret = vsnprintf(str, maxsize-SNPRINTF_SIZE_CORR, format, cp);
+ va_end(cp);
if (ret == maxsize-1)
ret = -1;
}