From 33baa8f3823cd0501aa091b51cd9f5fb9f32a738 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 23 Apr 2014 18:37:08 -0700 Subject: [PATCH] Fix the error when formatting a float with a filled buffer on MSVC. --- format.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/format.cc b/format.cc index ad970355..671cc017 100644 --- a/format.cc +++ b/format.cc @@ -320,6 +320,15 @@ void fmt::BasicWriter::FormatDouble( Char fill = static_cast(spec.fill()); for (;;) { std::size_t size = buffer_.capacity() - offset; +#if _MSC_VER + // MSVC's vsnprintf_s doesn't work with zero size, so reserve + // space for at least one extra character to make the size non-zero. + // Note that the buffer's capacity will increase by more than 1. + if (size == 0) { + buffer_.reserve(offset + 1); + size = buffer_.capacity() - offset; + } +#endif Char *start = &buffer_[offset]; int n = internal::CharTraits::FormatFloat( start, size, format, width_for_sprintf, precision, value);