From f9e3afaad2296e8061b44f55152d2be14f072c57 Mon Sep 17 00:00:00 2001 From: Lirusaito Date: Thu, 21 Feb 2019 03:22:54 -0500 Subject: [PATCH] Revert "Do llformat even better!" This reverts commit 4f87e82a19c15d626bdcd4eac2ad80b4a1d7cd9a. string::data can't be nonconst until C++17, maybe one day. --- indra/llcommon/llformat.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/indra/llcommon/llformat.cpp b/indra/llcommon/llformat.cpp index 57b74cc70..319afda94 100644 --- a/indra/llcommon/llformat.cpp +++ b/indra/llcommon/llformat.cpp @@ -37,24 +37,26 @@ #include -constexpr auto smallsize = 1024; // common used function with va_list argument // wrapper for vsnprintf to be called from llformatXXX functions. -static void va_format(std::string& charvector, const char *fmt, va_list va) +static void va_format(std::string& out, const char *fmt, va_list va) { + constexpr auto smallsize = 1024; + std::vector charvector(smallsize); // Evolves into charveleon va_list va2; va_copy(va2, va); const auto size = std::vsnprintf(charvector.data(), charvector.size(), fmt, va); - if (size >= smallsize) // Evolve into charveleon + if (size >= smallsize) { charvector.resize(1+size); // Use the String Stone std::vsnprintf(charvector.data(), charvector.size(), fmt, va2); } + out.assign(charvector.data()); } std::string llformat(const char *fmt, ...) { - std::string res(smallsize, '\0'); + std::string res; va_list va; va_start(va, fmt); va_format(res, fmt, va); @@ -64,7 +66,7 @@ std::string llformat(const char *fmt, ...) std::string llformat_to_utf8(const char *fmt, ...) { - std::string res(smallsize, '\0'); + std::string res; va_list va; va_start(va, fmt); va_format(res, fmt, va);