mirror of
https://github.com/corda/corda.git
synced 2025-01-19 03:06:36 +00:00
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:
parent
ef11cd1d8d
commit
5241660463
@ -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]);
|
||||
|
Loading…
Reference in New Issue
Block a user