From 90845974ea26829aa167a9170ff87008eb41d688 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 23 Apr 2018 23:52:18 +0200 Subject: [PATCH] nasal/lib.c: Make copy of va_list for each traversal It's not portable to traverse a va_list more than once. --- simgear/nasal/lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/simgear/nasal/lib.c b/simgear/nasal/lib.c index 796c3ca3..528803b5 100644 --- a/simgear/nasal/lib.c +++ b/simgear/nasal/lib.c @@ -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; }