From 3eacc470851a28587d0165a94f1e24b1c8e9a9d2 Mon Sep 17 00:00:00 2001 From: William Pettersson Date: Mon, 20 Sep 2021 10:17:51 +0100 Subject: [PATCH] util/logging: Don't reuse vargs (#632) As vargs may be modified by some functions, we should not reuse it and instead create a copy of it. This fixes a segfault on logging calls happening with GCC, and potentially may fix other compilers and platforms as well. --- source/util/util-logging.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/util/util-logging.cpp b/source/util/util-logging.cpp index 5cc3298..8c3cfa7 100644 --- a/source/util/util-logging.cpp +++ b/source/util/util-logging.cpp @@ -34,11 +34,14 @@ void streamfx::util::logging::log(level lvl, const char* format, ...) va_list vargs; va_start(vargs, format); + va_list vargs_copy; + va_copy(vargs_copy, vargs); int32_t ret = vsnprintf(buffer.data(), buffer.size(), format, vargs); buffer.resize(ret + 1); - ret = vsnprintf(buffer.data(), buffer.size(), format, vargs); + ret = vsnprintf(buffer.data(), buffer.size(), format, vargs_copy); va_end(vargs); + va_end(vargs_copy); blog(level_map.at(lvl), "[StreamFX] %s", buffer.data()); }