From 3b3093c72eaf3cacbb0a1411b9551706e52009bf Mon Sep 17 00:00:00 2001 From: Scott Giese Date: Sat, 15 Jun 2019 11:54:35 -0500 Subject: [PATCH] [nasal] remediate segfault in lib.c state of vaCopy is altered during each usage, so it needs to be discarded and not reused by multiple calls. --- simgear/nasal/lib.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/simgear/nasal/lib.c b/simgear/nasal/lib.c index 87e6bd6b..0322492f 100644 --- a/simgear/nasal/lib.c +++ b/simgear/nasal/lib.c @@ -302,23 +302,28 @@ static naRef f_die(naContext c, naRef me, int argc, naRef* args) static char* dosprintf(char* f, ...) { char* buf; + va_list va; - int len = 0; va_start(va, f); - va_list vaCopy; - va_copy(vaCopy, va); - len = vsnprintf(0, 0, f, vaCopy); + + int len = vsnprintf(0, 0, f, va); + va_end(va); + if (len <= 0) { - buf = naAlloc(2); + buf = (char *) naAlloc(2); *buf = 0; } else { len++;// allow for terminating null - buf = naAlloc(len); - len = vsnprintf(buf, len, f, vaCopy); + buf = (char *) naAlloc(len); + + va_list va; + va_start(va, f); + + len = vsnprintf(buf, len, f, va); + va_end(va); } - va_end(va); - va_end(vaCopy); + return buf; }