Skip to content

Commit

Permalink
Fix initialization of iterator_buffer (#1996)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Nov 8, 2020
1 parent 2435ea4 commit 5bedcb6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand Down
7 changes: 7 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1992,21 +1992,28 @@ 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';
result = fmt::format_to_n(buffer, 3, "{}", 'A');
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) {
Expand Down

0 comments on commit 5bedcb6

Please sign in to comment.