From e54033feb0fd6d4a480ed6e87a108f4d7cfb6218 Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sat, 31 Jan 2026 01:12:11 +0800 Subject: [PATCH 1/3] Fix off-by-one error in `__std_get_cvt` Co-authored-by: AZero13 --- stl/src/format.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/format.cpp b/stl/src/format.cpp index 67a91356a9d..527d4bed3dc 100644 --- a/stl/src/format.cpp +++ b/stl/src/format.cpp @@ -31,7 +31,7 @@ extern "C" [[nodiscard]] __std_win_error __stdcall __std_get_cvt( break; } - for (unsigned char _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First != _Last; ++_First) { + for (unsigned char _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First <= _Last; ++_First) { _Pcvt->_Isleadbyte[_First >> 3] |= 1u << (_First & 0b111u); } } From 624c34066584a06c806c3a4735328d3c7130e4ab Mon Sep 17 00:00:00 2001 From: cpplearner Date: Sat, 31 Jan 2026 01:32:00 +0800 Subject: [PATCH 2/3] Add testcase --- .../test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P2286R8_text_formatting_escaping_legacy_text_encoding/test.cpp b/tests/std/tests/P2286R8_text_formatting_escaping_legacy_text_encoding/test.cpp index b01f72fae10..44ac16c52e4 100644 --- a/tests/std/tests/P2286R8_text_formatting_escaping_legacy_text_encoding/test.cpp +++ b/tests/std/tests/P2286R8_text_formatting_escaping_legacy_text_encoding/test.cpp @@ -15,6 +15,8 @@ void test_escaped_string() { assert(format("{:?}", "\xEB!") == "\"\\x{eb}!\""); assert(format("{:?}", "\x81\x40\x40\x81") == "\"\\u{3000}\x40\\x{81}\""); + + assert(format("{:?}", "\xFC\x4B") == "\"\u9ED1\""); } template From 9a2a09890e657392b646d45941fd7c8ccbf03b8c Mon Sep 17 00:00:00 2001 From: "S. B. Tam" Date: Sat, 31 Jan 2026 02:34:42 +0800 Subject: [PATCH 3/3] Avoid wrap around if `_Last` is 255 --- stl/src/format.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/src/format.cpp b/stl/src/format.cpp index 527d4bed3dc..d639183985a 100644 --- a/stl/src/format.cpp +++ b/stl/src/format.cpp @@ -31,7 +31,7 @@ extern "C" [[nodiscard]] __std_win_error __stdcall __std_get_cvt( break; } - for (unsigned char _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First <= _Last; ++_First) { + for (unsigned int _First = _Info.LeadByte[_Idx], _Last = _Info.LeadByte[_Idx + 1]; _First <= _Last; ++_First) { _Pcvt->_Isleadbyte[_First >> 3] |= 1u << (_First & 0b111u); } }