diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 1a1428ea..ec5da1db 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -1292,9 +1292,12 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { for (auto end = p + s.size() - block_size + 1; p < end;) p = transcode(p); } if (auto num_chars_left = s.data() + s.size() - p) { - char buf[4] = {}; + char buf[2 * block_size - 1] = {}; memcpy(buf, p, num_chars_left); - transcode(buf); + p = buf; + do { + p = transcode(p); + } while (p - buf < num_chars_left); } buffer_.push_back(0); } diff --git a/test/format-test.cc b/test/format-test.cc index cd2653b1..050a442e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -410,6 +410,7 @@ TEST(UtilTest, UTF8ToUTF16) { "invalid utf8"); EXPECT_THROW_MSG(fmt::internal::utf8_to_utf16(fmt::string_view("ะป", 1)), std::runtime_error, "invalid utf8"); + EXPECT_EQ(L"123456", fmt::internal::utf8_to_utf16("123456").str()); } TEST(UtilTest, UTF8ToUTF16EmptyString) {