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.
This commit is contained in:
William Pettersson 2021-09-20 10:17:51 +01:00 committed by Michael Fabian 'Xaymar' Dirks
parent 04c7116f5a
commit 3eacc47085

View file

@ -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());
}