From 5b80f24830c703b229715c0ed63dde16504f175f Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 8 Feb 2024 14:16:36 +0100 Subject: [PATCH] string: fix vsnprintf on macOS vsnprintf_l and vswprintf_l mutate va_list parameter on some versions of macOS (11.7 Big Sur). This makes it impossible to call printf multiple times with a growing buffer. Signed-off-by: Simon Rozman --- include/stdex/string.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 986f7365a..0a6bcc9b7 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -2328,7 +2328,9 @@ namespace stdex #pragma warning(suppress: 4996) return _vsnprintf_l(str, capacity, format, locale, arg); #else - return ::vsnprintf_l(str, capacity, locale, format, arg); + va_list arg_mutable; + va_copy(arg_mutable, arg); + return ::vsnprintf_l(str, capacity, locale, format, arg_mutable); #endif } @@ -2338,7 +2340,9 @@ namespace stdex #pragma warning(suppress: 4996) return _vsnwprintf_l(str, capacity, format, locale, arg); #else - return ::vswprintf_l(str, capacity, locale, format, arg); + va_list arg_mutable; + va_copy(arg_mutable, arg); + return ::vswprintf_l(str, capacity, locale, format, arg_mutable); #endif } /// \endcond