From d1f31d6fda723e2bd1fb60bca8bb55e7acf630c8 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 27 Aug 2015 02:57:00 +0300 Subject: [PATCH] fmt::format fixed --- Utilities/StrFmt.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 541f1007f5..8465ad0612 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -242,13 +242,13 @@ namespace fmt // fixed stack buffer for the first attempt std::array fixed_buf; - // possibly dynamically allocated buffer for additional attempts + // possibly dynamically allocated buffer for the second attempt std::unique_ptr buf; // pointer to the current buffer char* buf_addr = fixed_buf.data(); - for (std::size_t buf_size = fixed_buf.size();; buf.reset(buf_addr = new char[buf_size])) + for (std::size_t buf_size = fixed_buf.size();;) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" @@ -261,12 +261,12 @@ namespace fmt throw std::runtime_error("std::snprintf() failed"); } - if (len <= buf_size) + if (len < buf_size) { return{ buf_addr, len }; } - buf_size = len; + buf.reset(buf_addr = new char[buf_size = len + 1]); } }