fix(libc): ignore the space and plus flags on wide unsigned conversions #9959

Merged
JJenkx merged 2 commits from upstream-pr/9959 into main 2026-10-26 21:30:08 +00:00
JJenkx commented 2026-10-23 00:15:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-23T00:15:32Z.


What

The wide printf family (swprintf and the rest) hands %o, %u, %x and %X to the host with the guest's flags. The UCRT honours a space flag on %u, so swprintf(u"[% u]", 7u) gave [ 7] on Windows. The libc.prx that 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, main cd435c58f4.

  • Differential run: a scratch loader runs a title's decrypted libc.prx natively and compares its swprintf (nJz16JE1txM) with this build's swprintf_nid_postfix. It uses 349,085 random integer formats: random - + space # 0 flags, width and precision 0–24, d i u o x X c and every length modifier except q, with random 64-bit, small and zero values.

    • On main, the u conversions differ at every length: between 1,041 and 2,411 formats each.
    • With this change no d, i, u, o, x or X format differs. The copies bundled with PPSA07923, PPSA05916 and PPSA13934 give the same result.
    • The %c differences that remain (a byte of 0x80 or more) are a separate change.
  • guest_wide_formatting: the new CheckUnsignedSignFlags checks [% 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. With main's FormattingWide.cpp and this test, guest_wide_formatting aborts.

  • python tools/check_conventions.py --base origin/main and git diff --check pass.

  • 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_formatting passed 1/1 with this PR's FormattingWide.cpp and GuestWideFormatting.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): a034cceacdbe77694853524abce487a06937b016 in 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. Built guest_formatting_tests and guest_wide_formatting_tests; ctest --test-dir <build> -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120 passed 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

  • Based on current main; no other open PR changes the wide unsigned flags
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source: none
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4975895677 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9959). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-23T00:15:32Z. --- ### What The wide printf family (`swprintf` and the rest) hands `%o`, `%u`, `%x` and `%X` to the host with the guest's flags. The UCRT honours a space flag on `%u`, so `swprintf(u"[% u]", 7u)` gave `[ 7]` on Windows. The `libc.prx` that 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`, `main` cd435c58f4. - **Differential run:** a scratch loader runs a title's decrypted `libc.prx` natively and compares its `swprintf` (`nJz16JE1txM`) with this build's `swprintf_nid_postfix`. It uses 349,085 random integer formats: random `- + space # 0` flags, width and precision 0–24, `d i u o x X c` and every length modifier except `q`, with random 64-bit, small and zero values. - On `main`, the `u` conversions differ at every length: between 1,041 and 2,411 formats each. - With this change no `d`, `i`, `u`, `o`, `x` or `X` format differs. The copies bundled with PPSA07923, PPSA05916 and PPSA13934 give the same result. - The `%c` differences that remain (a byte of 0x80 or more) are a separate change. - **`guest_wide_formatting`:** the new `CheckUnsignedSignFlags` checks `[% 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. With `main`'s `FormattingWide.cpp` and this test, `guest_wide_formatting` aborts. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - Not tested on a physical console. - **Linux (reviewer run):** [MarcZX10 ran a focused Linux check](https://github.com/boykopovar/AnyPS5/pull/9959#issuecomment-6354333925) in an existing configured Release build with GCC 12: `guest_wide_formatting` passed 1/1 with this PR's `FormattingWide.cpp` and `GuestWideFormatting.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):** `a034cceacdbe77694853524abce487a06937b016` in 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. Built `guest_formatting_tests` and `guest_wide_formatting_tests`; `ctest --test-dir <build> -R '^guest_(wide_)?formatting$' -V --no-tests=error --timeout 120` passed **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 - [x] Based on current `main`; no other open PR changes the wide unsigned flags - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source: none - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code).
MarcZX10 commented 2026-10-23 00:22:49 +00:00 (Migrated from github.com)

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 into spec, drops only space and plus for unsigned integer conversions, and preserves width, precision, #, 0 and -; 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_formatting passed 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5622510500 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9959#pullrequestreview-5622510500). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T00:22:49Z. **Review:** APPROVED --- Reviewed exact head `a034cceacdbe77694853524abce487a06937b016`. The formatter parses the supported flags into `spec`, drops only space and plus for unsigned integer conversions, and preserves width, precision, `#`, `0` and `-`; 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_formatting` passed 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9959
No description provided.