Skip to content

Commit

Permalink
Merge branch 'jk/maint-snprintf-va-copy'
Browse files Browse the repository at this point in the history
* jk/maint-snprintf-va-copy:
  compat/snprintf: don't look at va_list twice
  • Loading branch information
Junio C Hamano committed Dec 20, 2011
2 parents b052781 + a9bfbc5 commit ea4ef30
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions compat/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
}
Expand Down

0 comments on commit ea4ef30

Please sign in to comment.