Can't use the same va_list twice, from Emanuele Giaquinta.

pull/1/head
Nicholas Marriott 2011-07-25 09:56:43 +00:00
parent 5339b8ce3a
commit e9ebdac3dd
1 changed files with 4 additions and 1 deletions

View File

@ -44,12 +44,15 @@ int
vasprintf(char **ret, const char *fmt, va_list ap)
{
int n;
va_list ap2;
va_copy(ap2, ap);
if ((n = vsnprintf(NULL, 0, fmt, ap)) < 0)
goto error;
*ret = xmalloc(n + 1);
if ((n = vsnprintf(*ret, n + 1, fmt, ap)) < 0) {
if ((n = vsnprintf(*ret, n + 1, fmt, ap2)) < 0) {
xfree(*ret);
goto error;
}