From 03f0ef778f68bc5a59617ca09e9cb25a177ff958 Mon Sep 17 00:00:00 2001 From: rlar Date: Sat, 12 Apr 2014 20:37:36 +0200 Subject: [PATCH] bug fix, need va_copy() when reusing a va_list --- src/include/ngspice/ngspice.h | 5 +++++ src/sharedspice.c | 6 +++++- src/tclspice.c | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/include/ngspice/ngspice.h b/src/include/ngspice/ngspice.h index dd0f3f69f..df1152419 100644 --- a/src/include/ngspice/ngspice.h +++ b/src/include/ngspice/ngspice.h @@ -304,4 +304,9 @@ void soa_printf(CKTcircuit *ckt, GENinstance *instance, const char *fmt, ...); #define NG_IGNOREABLE(x) (void)x +#if !defined(va_copy) && defined(_MSC_VER) +#define va_copy(dst, src) ((dst) = (src)) +#endif + + #endif diff --git a/src/sharedspice.c b/src/sharedspice.c index f93008feb..4649db8a8 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -939,7 +939,11 @@ sh_vfprintf(FILE *f, const char *fmt, va_list args) // assert(size > 0); for (;;) { - nchars = vsnprintf(p, size, fmt, args); + va_list ap; + + va_copy(ap, args); + nchars = vsnprintf(p, size, fmt, ap); + va_end(ap); if(nchars == -1) { // compatibility to old implementations size *= 2; diff --git a/src/tclspice.c b/src/tclspice.c index bec11a907..2dbbaae62 100644 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -2669,7 +2669,11 @@ tcl_vfprintf(FILE *f, const char *fmt, va_list args) // assert(size > 0); for (;;) { - nchars = vsnprintf(p + prolog_len, size, fmt, args); + va_list ap; + + va_copy(ap, args); + nchars = vsnprintf(p + prolog_len, size, fmt, ap); + va_end(ap); if(nchars == -1) { /* compatibility to old implementations */ size *= 2;