Repository navigation
fix(libc): print a non-ASCII unit after % in the wide printf family instead of failing - #23884
Merged
oneandonlydean merged 1 commit intoNov 19, 2026
Conversation
…nstead of failing A % followed by a unit from 0x80 up, such as a kana or an ideograph, made the whole wide printf call fail, while an unknown ASCII letter and a high surrogate were already printed as literal text. Treat every unit from 0x80 up as the unknown conversion it is. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PrivacyOnion
approved these changes
Nov 19, 2026
PrivacyOnion
left a comment
Contributor
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 002c12f88d:
- Conventions:
tools/check_conventions.pypassed. - Build:
guest_wide_formatting_testsbuilt cleanly. - CTest (
guest_wide_formatting):1/1 Test #1161: guest_wide_formatting ............ Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libc/src/FormattingWide.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #1161: guest_wide_formatting ............Subprocess aborted***Exception: 0.80 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- FormattingWide.cpp: verified condition 'conversion == u'S' || conversion >= 0x80 || !std::strchr(LibcDetail::KnownConversions, static_cast(conversion))' correctly handles non-ASCII units >= 0x80 without invoking std::strchr with out-of-range char values
- FormattingWide.cpp: verified lone surrogates, surrogate pairs, ideographs, and Latin-1/kana non-ASCII units take the fallback literal branch and preserve formatting/arguments correctly
- FormattingWide.cpp: verified trailing % and incomplete conversion handling (throws std::invalid_argument) remain fully protected before reaching this branch
- GuestWideFormatting.cpp: verified test assertions properly exercise non-ASCII conversions, width padding, alignment, argument ordering, and lone surrogates
- docs/dev/debt/changes/fix-libc-wide-printf-non-ascii-conversion.md: verified debt fragment adheres to format and documents console probe behavior
Looks Good To Me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
In the wide
printffamily (swprintf,vswprintf,wprintf,fwprintfand their_sforms, all throughFormatWideInto), a%followed by a 16-bit unit from 0x80 up made the whole call fail:FormatWideIntothrewUnsupported format conversion, whichvswprintfturns into a failure, soswprintf(buf, n, L"100%完")returned a negative value and left the buffer empty. A title that puts a literal percent sign in front of a kana, an ideograph or an accented letter in a wide format string got no text at all.The same function already prints an unknown conversion as literal text:
%and the character, padded to the width. That is the rule measured on the console'slibSceLibcInternal.sprxfor%y,%m,%Dand others (#5303), and the tests extend it to a high surrogate (%😀prints%😀, a lone0xd83dprints as itself). The branch that implements it testedconversion < 0x80 && unknownor0xd800 <= conversion < 0xdc00, which left every other unit from 0x80 up, a lone low surrogate included, to the finalthrow. The narrow family has no such hole:FormatWindowstreats any byte that is not a known conversion as unknown.This PR makes every unit from 0x80 up take the unknown-conversion branch. Nothing else changes: the known conversions, the trailing-
%and incomplete-conversion rejections and%nare decided before or by the samestrchrtest as before (a NUL conversion is rejected earlier, atIncomplete format conversion).Not measured on a console: like the surrogate case and the other forms its debt entry lists as "by extension", this follows the measured rule for unknown ASCII letters. The
The wide printf familydebt entry now says so.Tested
Windows 11 IoT Enterprise LTSC 2024 (10.0.26100), WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON.core/libs/tests/GuestWideFormatting.cppnext to the surrogate ones: an ideograph after100%, a right-aligned%4é, a left-aligned%-4で, two real%darguments around the non-ASCII unknown conversions%\x80and%¥(the arguments still line up), and a lone low surrogate0xdc00.main01b7264270andFormattingWide.cppunchanged,guest_wide_formattingfails at the first new check,swprintf ideograph as an unknown conversion.mainfd6d6f4a84),guest_wide_formattingpasses, andctest -R "^guest_(wide|.*format|.*printf|.*scan|standard_stream|wcs)"passes 35 of 35.python tools/check_conventions.py --base origin/mainandpython tools/debt_fold.py --checkpass.python tools/pr_overlap.py --branchcould not compare fix(libc): write a 36-byte struct tm as the console does #10409, which conflicts withmainonGuestWideFormatting.cpp; compared by hand, it removes one line of that test for itsstruct tmchange and does not touch the wide formatter.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)