fix(libc): ignore the space and plus flags on wide unsigned conversions #9959
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9959"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T00:15:32Z.
What
The wide printf family (
swprintfand the rest) hands%o,%u,%xand%Xto the host with the guest's flags. The UCRT honours a space flag on%u, soswprintf(u"[% u]", 7u)gave[ 7]on Windows. Thelibc.prxthat titles ship applies the space and plus flags to signed conversions only and gives[7], at every length (% hhu,% lu,% llu,% zu,% ju,% tu). The narrow family already matched.This drops
+and space from the flags of an unsigned conversion before the host formats it.#,0,-, width and precision are unchanged.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,maincd435c58f4.Differential run: a scratch loader runs a title's decrypted
libc.prxnatively and compares itsswprintf(nJz16JE1txM) with this build'sswprintf_nid_postfix. It uses 349,085 random integer formats: random- + space # 0flags, width and precision 0–24,d i u o x X cand every length modifier exceptq, with random 64-bit, small and zero values.main, theuconversions differ at every length: between 1,041 and 2,411 formats each.d,i,u,o,xorXformat differs. The copies bundled with PPSA07923, PPSA05916 and PPSA13934 give the same result.%cdifferences that remain (a byte of 0x80 or more) are a separate change.guest_wide_formatting: the newCheckUnsignedSignFlagschecks[% u|%+u|% lu|% 5u|%+x|% #o], which gives[7|7|7| 7|7|07]on the console. The libc formatting, scanning, stream, wide-character and string tests (34) pass in three runs out of three. Withmain'sFormattingWide.cppand this test,guest_wide_formattingaborts.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not tested on a physical console.
Linux (reviewer run): MarcZX10 ran a focused Linux check in an existing configured Release build with GCC 12:
guest_wide_formattingpassed 1/1 with this PR'sFormattingWide.cppandGuestWideFormatting.cpp. That reused an older configured tree with the PR's sources overlaid, so it is a focused Linux run, not a clean CI build.Linux (exact PR commit):
a034cceacdbe77694853524abce487a06937b016in a fresh detached worktree with initialized submodules and a newly configured Ninja Release build (BUILD_TESTING=ON,ANYPS5_RELINKER_CLI=ON,ANYPS5_ENABLE_SPIRV_TOOLS=OFF), GCC 16.2.1 20260810, glibc 2.44. Builtguest_formatting_testsandguest_wide_formatting_tests;ctest --test-dir <build> -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120passed 2/2 in each of three runs, with no skipped tests. This verifies the complete two focused executables at this PR commit; it is not a full product build, a new console differential run, or a test against latest main. No negative control was run in this Linux job.Checklist
main; no other open PR changes the wide unsigned flagsNotImplemented_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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T00:22:49Z.
Review: APPROVED
Reviewed exact head
a034cceacdbe77694853524abce487a06937b016. The formatter parses the supported flags intospec, drops only space and plus for unsigned integer conversions, and preserves width, precision,#,0and-; the added assertions check the resulting wide output. The reported Windows console differential covers 349,085 randomized formats and reports matching d/i/u/o/x/X behavior on the change. I also built and ran the exact PR formatter/test sources on Linux/glibc:guest_wide_formattingpassed 1/1 (the configured surrounding build tree is older than current main; the two overlaid source files match current-main versions). Exact-head diff-check and conventions pass. Hosted relinker, ASan, context and write-watch checks pass; hosted product tests are skipped by policy.