fix(libc): print unknown printf conversions and ' as titles' libc.prx does #11907

Merged
JJenkx merged 1 commit from upstream-pr/11907 into main 2026-11-04 04:49:38 +00:00
JJenkx commented 2026-10-27 12:24:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-27T12:24:08Z.


What

Two differences from the libc.prx that titles ship, in how the printf family handles conversions it does not know.

' is not a flag there. #3567 made ' FreeBSD's grouping flag, from FreeBSD's documentation. The titles' copy treats ' as an unknown conversion character: %'d prints %'d and consumes no argument. On main, printf("%'d|%d", 11, 22) prints 11|22. On the console it prints %'d|11, so every later conversion reads a different argument.

Flags on unknown conversions. main throws for an unknown conversion with +, space or ', or with 0 and a width, and for any unknown conversion in the _s forms. The wide family returns -1. The titles' copy prints % and the character:

  • it ignores +, space, #, 0 and the precision;
  • it pads to the width with spaces, on the left with -;
  • * still consumes its int;
  • the _s forms behave the same.
Format Titles' copy main
`%'d %d` with 11, 22 `%'d
[%-'5d] with 11 [%'5d] [11 ]
%+5k, %05k, % k %k, %k, %k throws
`% +#0-7k ` `%k
snprintf_s %k, `%5k ` %k, ` %k
swprintf %5k, %-04k, %+.2k %k, %k , %k -1

Both formatters now treat ' as a conversion character and print unknown conversions this way in every form. On Linux, RequiresGuestFormatting sends a format containing ' to the guest formatter instead of glibc. The printf family conversions debt entry now states the measured rule in place of "unverified and throw".

Tested

Latest Linux qualification (2026-11-02): exact head 8cac89f55a87191359f990f27952ecc1dd3cfbfe on pinned main a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8. Resolved printf debt against main while retaining the measured unknown-conversion/flag behavior and main’s new thread-exit registration entry. Production and test blobs equal the automatic integration.

3 focused groups repeated three times: 9 passes, zero skips. Public headers, conventions, whitespace, raw libc/test builds and the actual production NID-patching command passed. MinGW syntax passed for Formatting.cpp, FormattingWide.cpp. No new Windows/macOS runtime, bundled-SDK reference, native title, GPU or performance claim; earlier evidence retains its historical pins.

Earlier pinned qualifications follow.

Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, BUILD_TESTING=ON. The base is #11893 17c950f0a5 (on main 8ff4baf534).

  • Comparison: a scratch loader runs the decrypted libc.prx of PPSA07923 and PPSA13934 natively.
    • Each row above, and each new expected string, was printed by both titles with the function it names or that its test calls (snprintf, snprintf_s, swprintf or snwprintf_s). The two titles agree on every one.
    • ' behaves the same before d u x ld f g s and after +, 0 or a precision. %''d prints %''d.
  • guest_formatting:
    • #3567's %'d|%'u|%'.2f|%'-8ld|%'+05d|%'g check now expects the format text, with no arguments.
    • Its %'lld %'zu and %'d %ls checks are replaced by [%6'd][%-6'd] and %'d %ls|%d, with arguments valid on the console.
    • A new line checks padded and flagged unknown conversions. The vsnprintf_s %y check now expects [%y][%k ] instead of a throw.
  • guest_wide_formatting:
    • CheckGroupingFlag now expects the format text from swprintf and snwprintf_s, plus padded unknown conversions.
    • The old swprintf %q check expected failure. It now expects [%q][ %q], which the titles' swprintf prints, measured on PPSA07923 and PPSA13934.
  • guest_formatting, guest_wide_formatting and guest_stdio_variadic pass in each of 3 runs on the exact head 15b33e8e76.
  • Negative control: with #11893's WindowsFormatting.hpp, Formatting.cpp and FormattingWide.cpp and these tests, guest_formatting and guest_wide_formatting abort (exit 0xc0000409). guest_stdio_variadic passes there too.
  • python tools/check_conventions.py --base origin/main and git diff --check pass.
  • Linux: MarcZX10 built this exact head on Linux (GCC 12.2.0, Release); guest_formatting, guest_wide_formatting and guest_stdio_variadic pass 3/3 (review). That covers the RequiresGuestFormatting routing change.
  • Not tested: a console and macOS. A % right at the end of a format still throws, since the console reads past the terminator there.

Checklist

  • Based on current main; no other open PR implements the same functions. Stacked on #11893, which is based on main 8ff4baf534; it will follow #11893's rebase onto current main
  • 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 (#11893 has merged; its measured changes and actual parent history remain part of this stack)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5033838181 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11907). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-27T12:24:08Z. --- ### What Two differences from the `libc.prx` that titles ship, in how the printf family handles conversions it does not know. **`'` is not a flag there.** #3567 made `'` FreeBSD's grouping flag, from FreeBSD's documentation. The titles' copy treats `'` as an unknown conversion character: `%'d` prints `%'d` and consumes no argument. On `main`, `printf("%'d|%d", 11, 22)` prints `11|22`. On the console it prints `%'d|11`, so every later conversion reads a different argument. **Flags on unknown conversions.** `main` throws for an unknown conversion with `+`, space or `'`, or with `0` and a width, and for any unknown conversion in the `_s` forms. The wide family returns -1. The titles' copy prints `%` and the character: - it ignores `+`, space, `#`, `0` and the precision; - it pads to the width with spaces, on the left with `-`; - `*` still consumes its `int`; - the `_s` forms behave the same. | Format | Titles' copy | `main` | |---|---|---| | `%'d|%d` with 11, 22 | `%'d|11` | `11|22` | | `[%-'5d]` with 11 | `[%'5d]` | `[11 ]` | | `%+5k`, `%05k`, `% k` | ` %k`, ` %k`, `%k` | throws | | `% +#0-7k|` | `%k |` | throws | | `snprintf_s` `%k`, `%5k|` | `%k`, ` %k|` | throws | | `swprintf` `%5k`, `%-04k`, `%+.2k` | ` %k`, `%k `, `%k` | -1 | Both formatters now treat `'` as a conversion character and print unknown conversions this way in every form. On Linux, `RequiresGuestFormatting` sends a format containing `'` to the guest formatter instead of glibc. The `printf family conversions` debt entry now states the measured rule in place of "unverified and throw". ### Tested Latest Linux qualification (2026-11-02): exact head `8cac89f55a87191359f990f27952ecc1dd3cfbfe` on pinned main `a4eca2a056bf3bbbec98ab42e9d28163e4ea9cb8`. Resolved printf debt against main while retaining the measured unknown-conversion/flag behavior and main’s new thread-exit registration entry. Production and test blobs equal the automatic integration. 3 focused groups repeated three times: **9 passes, zero skips**. Public headers, conventions, whitespace, raw libc/test builds and the actual production NID-patching command passed. MinGW syntax passed for Formatting.cpp, FormattingWide.cpp. No new Windows/macOS runtime, bundled-SDK reference, native title, GPU or performance claim; earlier evidence retains its historical pins. Earlier pinned qualifications follow. Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, `BUILD_TESTING=ON`. The base is #11893 `17c950f0a5` (on `main` 8ff4baf534). - **Comparison:** a scratch loader runs the decrypted `libc.prx` of PPSA07923 and PPSA13934 natively. - Each row above, and each new expected string, was printed by both titles with the function it names or that its test calls (`snprintf`, `snprintf_s`, `swprintf` or `snwprintf_s`). The two titles agree on every one. - `'` behaves the same before `d u x ld f g s` and after `+`, `0` or a precision. `%''d` prints `%''d`. - **`guest_formatting`:** - #3567's `%'d|%'u|%'.2f|%'-8ld|%'+05d|%'g` check now expects the format text, with no arguments. - Its `%'lld %'zu` and `%'d %ls` checks are replaced by `[%6'd][%-6'd]` and `%'d %ls|%d`, with arguments valid on the console. - A new line checks padded and flagged unknown conversions. The `vsnprintf_s` `%y` check now expects `[%y][%k ]` instead of a throw. - **`guest_wide_formatting`:** - `CheckGroupingFlag` now expects the format text from `swprintf` and `snwprintf_s`, plus padded unknown conversions. - The old `swprintf` `%q` check expected failure. It now expects `[%q][ %q]`, which the titles' `swprintf` prints, measured on PPSA07923 and PPSA13934. - `guest_formatting`, `guest_wide_formatting` and `guest_stdio_variadic` pass in each of 3 runs on the exact head `15b33e8e76`. - **Negative control:** with #11893's `WindowsFormatting.hpp`, `Formatting.cpp` and `FormattingWide.cpp` and these tests, `guest_formatting` and `guest_wide_formatting` abort (exit 0xc0000409). `guest_stdio_variadic` passes there too. - `python tools/check_conventions.py --base origin/main` and `git diff --check` pass. - **Linux:** MarcZX10 built this exact head on Linux (GCC 12.2.0, Release); `guest_formatting`, `guest_wide_formatting` and `guest_stdio_variadic` pass 3/3 ([review](https://github.com/boykopovar/AnyPS5/pull/11907#pullrequestreview-5667041399)). That covers the `RequiresGuestFormatting` routing change. - **Not tested:** a console and macOS. A `%` right at the end of a format still throws, since the console reads past the terminator there. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions. Stacked on #11893, which is based on `main` `8ff4baf534`; it will follow #11893's rebase onto current `main` - [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 (#11893 has merged; its measured changes and actual parent history remain part of this stack) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code).
MarcZX10 commented 2026-10-27 12:29:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:29:49Z.

Review: COMMENTED


I built the exact head 15b33e8e76 on Linux (GCC 12.2.0, Release) after initializing the declared submodules and configured XRandR support. The focused tests passed: guest_formatting, guest_wide_formatting, and guest_stdio_variadic (3/3). This covers the changed Linux routing as well as the narrow/wide formatter behavior. The hosted Windows/macOS and remaining platform jobs are still in progress, so I am leaving the final review decision until they complete.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5667041399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11907#pullrequestreview-5667041399). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T12:29:49Z. **Review:** COMMENTED --- I built the exact head `15b33e8e76` on Linux (GCC 12.2.0, Release) after initializing the declared submodules and configured XRandR support. The focused tests passed: `guest_formatting`, `guest_wide_formatting`, and `guest_stdio_variadic` (3/3). This covers the changed Linux routing as well as the narrow/wide formatter behavior. The hosted Windows/macOS and remaining platform jobs are still in progress, so I am leaving the final review decision until they complete.
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!11907
No description provided.