nasal/lib.c: Make copy of va_list for each traversal

It's not portable to traverse a va_list more than once.
This commit is contained in:
Tim Moore 2018-04-23 23:52:18 +02:00 committed by James Turner
parent 57fd817486
commit 90845974ea

View File

@ -302,15 +302,18 @@ static char* dosprintf(char* f, ...)
char* buf;
va_list va;
int olen, len = 16;
va_start(va, f);
while(1) {
buf = naAlloc(len);
va_start(va, f);
olen = vsnprintf(buf, len, f, va);
va_list vaCopy;
va_copy(vaCopy, va);
olen = vsnprintf(buf, len, f, vaCopy);
if(olen >= 0 && olen < len) {
va_end(va);
va_end(vaCopy);
return buf;
}
va_end(va);
va_end(vaCopy);
naFree(buf);
len *= 2;
}