From cb30f7639f29ec21214450094ea3ddd4f4505273 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 18:47:26 -0500 Subject: [PATCH] revert broken commit. Isaac doesn't know what he's doing. --- src/zm_utils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index bc17e5758..6ea4e0dae 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -120,16 +120,18 @@ std::string Join(const StringVector &values, const std::string &delim) { std::string stringtf(const char* format, ...) { va_list args; va_start(args, format); - int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0' - va_end(args); - - if (size <= 0) { - throw std::runtime_error("Error during formatting."); - } - - std::unique_ptr buf(new char[size]); va_list args2; va_copy(args2, args); + int size = vsnprintf(nullptr, 0, format, args); + va_end(args); + + if (size < 0) { + va_end(args2); + throw std::runtime_error("Error during formatting."); + } + size += 1; // Extra space for '\0' + + std::unique_ptr buf(new char[size]); vsnprintf(buf.get(), size, format, args2); va_end(args2);