From 896de392cdbc908bb1bcdc40cc68960a4cf944dd Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 24 Aug 2022 20:23:13 -0700 Subject: [PATCH] UI: Copy va_list in strprintf on non-Windows On operating systems other than Windows, va_list has to be copied when you pass it to a new function otherwise it becomes corrupted --- UI/nix-update/nix-update-helpers.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/UI/nix-update/nix-update-helpers.cpp b/UI/nix-update/nix-update-helpers.cpp index 69fb20cbd..d0b1dc7e1 100644 --- a/UI/nix-update/nix-update-helpers.cpp +++ b/UI/nix-update/nix-update-helpers.cpp @@ -4,22 +4,29 @@ std::string vstrprintf(const char *format, va_list args) { + va_list args2; + if (!format) return std::string(); + va_copy(args2, args); + std::string str; - int size = (int)vsnprintf(nullptr, 0, format, args) + 1; + int size = (int)vsnprintf(nullptr, 0, format, args2) + 1; str.resize(size); - vsnprintf(&str[0], size, format, args); + vsnprintf(&str[0], size, format, args2); + + va_end(args2); + return str; } std::string strprintf(const char *format, ...) { - std::string str; va_list args; va_start(args, format); + std::string str; str = vstrprintf(format, args); va_end(args);