From b11a7a106feb72aa348bb50a6d2c41ac8c2cbba7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 1 Feb 2020 11:04:29 +1000 Subject: [PATCH] Common/Log: Fix corrupted output/UB with va_copy Fixes crashes on GCC9+ (#9), maybe others. --- src/common/log.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/log.cpp b/src/common/log.cpp index 4b05bef5a..b5df001e4 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -321,10 +321,12 @@ void Writev(const char* channelName, const char* functionName, LOGLEVEL level, c va_copy(apCopy, ap); #ifdef WIN32 - u32 requiredSize = static_cast(_vscprintf(format, ap)); + u32 requiredSize = static_cast(_vscprintf(format, apCopy)); #else - u32 requiredSize = std::vsnprintf(nullptr, 0, format, ap); + u32 requiredSize = std::vsnprintf(nullptr, 0, format, apCopy); #endif + va_end(apCopy); + if (requiredSize < 256) { char buffer[256]; @@ -340,4 +342,4 @@ void Writev(const char* channelName, const char* functionName, LOGLEVEL level, c } } -} // namespace Log \ No newline at end of file +} // namespace Log