From: Adam Tkac Date: Tue, 3 Jun 2008 09:24:49 +0000 (+0000) Subject: Don't use one va_list variable twice in vsnprintf X-Git-Tag: v0.0.90~458 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=455ad979f95ac5084a5de02aefc9a4bc2686ba7c;p=tigervnc.git Don't use one va_list variable twice in vsnprintf git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2570 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/common/rfb/Logger.cxx b/common/rfb/Logger.cxx index 52d33085..6b9cfa31 100644 --- a/common/rfb/Logger.cxx +++ b/common/rfb/Logger.cxx @@ -41,6 +41,9 @@ static Mutex fpLock; static FILE* fp = 0; int vsnprintf(char *str, size_t n, const char *format, va_list ap) { + va_list ap_new; + int len, written; + str[0] = 0; if (!fp) { // Safely create a FILE* for /dev/null if there isn't already one @@ -51,15 +54,19 @@ int vsnprintf(char *str, size_t n, const char *format, va_list ap) fp = fopen("/dev/null","w"); if (!fp) return 0; } - int len = vfprintf(fp, format, ap); + + va_copy(ap_new, ap); + len = vfprintf(fp, format, ap_new); + va_end(ap_new); + if (len <= 0) return 0; CharArray s(len+1); vsprintf(s.buf, format, ap); - int written = __rfbmin(len, (int)n-1); + written = __rfbmin(len, (int)n-1); memcpy(str, s.buf, written); - str[written] = 0; + str[written] = '\0'; return len; } #endif