diff --git a/include/fmt/format.h b/include/fmt/format.h index 0903667c..9ecda111 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -546,6 +546,7 @@ constexpr auto to_pointer(OutputIt, size_t) -> T* { template auto to_pointer(basic_appender it, size_t n) -> T* { buffer& buf = get_container(it); auto size = buf.size(); + buf.try_reserve(size + n); if (buf.capacity() < size + n) return nullptr; buf.try_resize(size + n); return buf.data() + size; @@ -2317,15 +2318,13 @@ FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { if (negative) abs_value = ~abs_value + 1; int num_digits = count_digits(abs_value); auto size = (negative ? 1 : 0) + static_cast(num_digits); - auto it = reserve(out, size); - if (auto ptr = to_pointer(it, size)) { + if (auto ptr = to_pointer(out, size)) { if (negative) *ptr++ = static_cast('-'); format_decimal(ptr, abs_value, num_digits); return out; } - if (negative) *it++ = static_cast('-'); - it = format_decimal(it, abs_value, num_digits).end; - return base_iterator(out, it); + if (negative) *out++ = static_cast('-'); + return format_decimal(out, abs_value, num_digits).end; } // DEPRECATED!