fix SIGSEGV and off-by-one error in logDebug

We must use separate va_start/va_end pairs for each call to vsnprintf
on Linux and possibly other platforms in order to avoid a crash.
Also, we need to give it room to null terminate the string at the
right point.
This commit is contained in:
Joel Dice 2013-02-06 11:40:06 -07:00
parent ef11cd1d8d
commit 5241660463

View File

@ -4769,11 +4769,14 @@ logTrace(FILE* f, const char* fmt, ...)
#else
const unsigned length = vsnprintf(0, 0, fmt, a);
#endif
RUNTIME_ARRAY(char, buffer, length + 1);
vsnprintf(&buffer[0], length, fmt, a);
buffer[length] = 0;
va_end(a);
RUNTIME_ARRAY(char, buffer, length + 1);
va_start(a, fmt);
vsnprintf(&buffer[0], length + 1, fmt, a);
va_end(a);
buffer[length] = 0;
::fprintf(f, "%s", &buffer[0]);
#ifdef PLATFORM_WINDOWS
::OutputDebugStringA(&buffer[0]);