Skip to content

Conversation

@cpplearner
Copy link
Contributor

@cpplearner cpplearner commented Jan 31, 2026

This PR adds test case on top of #5943, and removes the check for out-of-range code points.

While _Mbrtowc is used by both <locale> and <format> facilities, only the former are affected because the <format> functions call the constexpr function _Decode_utf if the encoding is UTF-8.

I removed the check for out-of-range values because I think wch can't exceed 0xFFFF: there's an early return if the result won't fit in the Basic Multilingual Plane,

STL/stl/src/xmbtowc.cpp

Lines 110 to 115 in 3f76681

if (trailingUtf8Units > 2) { // this would result in a UTF-16 surrogate pair, which we can't emit in our
// singular output wchar_t, so fail
// see N4950 [locale.codecvt.virtuals]/3
errno = EILSEQ;
return -1;
}

SiliconA-Z and others added 3 commits December 6, 2025 10:39
Added UTF-8 validation in _Mbrtowc to reject overlong encodings and out-of-range code points, returning EILSEQ instead of accepting ill-formed sequences.
@cpplearner cpplearner requested a review from a team as a code owner January 31, 2026 12:46
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Jan 31, 2026
@StephanTLavavej
Copy link
Member

Thank you so much for figuring out how to salvage this! 😻 Now I finally understand what the issue is. I pushed additional test coverage.

@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Jan 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Ready To Merge

Development

Successfully merging this pull request may close these issues.

4 participants