diff --git a/sources/vasprintf.c b/sources/vasprintf.c index bec9a65..4050879 100644 --- a/sources/vasprintf.c +++ b/sources/vasprintf.c @@ -8,7 +8,13 @@ int vasprintf(char** strp, const char* format, va_list ap) { - int size = vsnprintf(NULL, 0, format, ap); + va_list ap2; + int size; + + /* the argument list is traversed twice */ + __va_copy(ap2, ap); + size = vsnprintf(NULL, 0, format, ap2); + va_end(ap2); if (size >= 0 && size < INT_MAX) { *strp = malloc(size + 1);