Fix initialization of iterator_buffer (#1996)

This commit is contained in:
Victor Zverovich 2020-11-08 08:08:55 -08:00
parent cc09f1a679
commit d1ef29d679
2 changed files with 8 additions and 1 deletions

View File

@ -784,7 +784,7 @@ class iterator_buffer final : public Traits, public buffer<T> {
public:
explicit iterator_buffer(OutputIt out, size_t n = buffer_size)
: Traits(n),
buffer<T>(data_, 0, n < size_t(buffer_size) ? n : size_t(buffer_size)),
buffer<T>(data_, 0, buffer_size),
out_(out) {}
~iterator_buffer() { flush(); }

View File

@ -1945,10 +1945,12 @@ TEST(FormatTest, FormatToN) {
EXPECT_EQ(5u, result.size);
EXPECT_EQ(buffer + 3, result.out);
EXPECT_EQ("123x", fmt::string_view(buffer, 4));
result = fmt::format_to_n(buffer, 3, "{:s}", "foobar");
EXPECT_EQ(6u, result.size);
EXPECT_EQ(buffer + 3, result.out);
EXPECT_EQ("foox", fmt::string_view(buffer, 4));
buffer[0] = 'x';
buffer[1] = 'x';
buffer[2] = 'x';
@ -1956,10 +1958,15 @@ TEST(FormatTest, FormatToN) {
EXPECT_EQ(1u, result.size);
EXPECT_EQ(buffer + 1, result.out);
EXPECT_EQ("Axxx", fmt::string_view(buffer, 4));
result = fmt::format_to_n(buffer, 3, "{}{} ", 'B', 'C');
EXPECT_EQ(3u, result.size);
EXPECT_EQ(buffer + 3, result.out);
EXPECT_EQ("BC x", fmt::string_view(buffer, 4));
result = fmt::format_to_n(buffer, 4, "{}", "ABCDE");
EXPECT_EQ(5u, result.size);
EXPECT_EQ("ABCD", fmt::string_view(buffer, 4));
}
TEST(FormatTest, WideFormatToN) {