Skip to content

fix(libc): follow measured wide printf behavior - #5303

Merged
oneandonlydean merged 8 commits into
boykopovar:mainfrom
MarcZX10:codex/wide-printf-extensions-5293
Nov 12, 2026
Merged

oneandonlydean merged 8 commits into
boykopovar:mainfrom
MarcZX10:codex/wide-printf-extensions-5293

Conversation

@MarcZX10

@MarcZX10 MarcZX10 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Updates non-secure guest wide printf formatting to match the measured literal-text behavior for %q, %D/%O/%U, unknown conversions, and width handling observed from libSceLibcInternal.sprx on firmware 12.70. The probe called swprintf from a payload process; it did not exercise a title or its bundled libc.prx, whose Dinkumware _Printf behavior remains unverified. The probe also showed that a trailing % read past the format terminator, so incomplete conversions continue to fail safely. The secure snwprintf_s path continues to reject these forms because its console behavior was not measured.

The original implementation commits retain Hussein Kadhim as author, and the original test commits retain MarcZX100. The review follow-up is authored by MarcZX10.

Tested

  • Current rebase: head 6de675ebf48b46bb5546a4c8a606e54ce480d08d is based on main 0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb; the existing authored commits were preserved. git diff --check, the conventions/template check, and the merge preview passed.
  • pr_test_quality.py emitted a possible-unregistered C++ test warning. Inspection of core/libs/prx/libc/CMakeLists.txt confirms that guest_wide_formatting_tests is registered with CTest as guest_wide_formatting.
  • Head 06bd24679818bec01461f191fec3e6d745ca88b6 built guest_wide_formatting_tests and passed ctest -R guest_wide_formatting --output-on-failure (1/1). Build and CTest were not rerun after rebasing.
  • No title libc.prx runtime test, Windows build or full test suite was run.

Checklist

  • Based on current main; no other open PR implements the same wide-format functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed under technical debt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Which title prints %q, %D/%O/%U, an unknown conversion or a trailing % through the wide printf family? The source here is FreeBSD 11.4, but the console's libc.prx formats through Dinkumware's _Printf, which can handle unknown conversions and q differently (same question as the review on #3987). Until a title reaches it, or _Printf in a title's libc.prx confirms these cases, main's throw is the safer behaviour.

@MarcZX10

Copy link
Copy Markdown
Contributor Author

I do not have title traces or Dinkumware _Printf evidence for these wide-format cases. The current evidence is FreeBSD 11.4 behavior and Linux-side tests, so I cannot claim console compatibility for %q, %D/%O/%U, unknown conversions, or a trailing %. I agree this leaves the added behavior unverified against the console; absent title or _Printf evidence, main’s throw is safer. I will avoid presenting these cases as title-required until we have that evidence.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 14, 2026
@adriadam10 adriadam10 self-assigned this Oct 14, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Blocking points:

  • The console's libc.prx formats through Dinkumware's _Printf, not FreeBSD's vfwprintf. As discussed above, neither a title nor _Printf evidence shows that %q, %D/%O/%U, unknown conversions (with width) or a trailing % behave as FreeBSD 11.4 does there; main's throw is the safe behaviour until then. Evidence that would unblock it: the relevant branches of _Printf disassembled from a title's libc.prx (same approach as in #3987), or a title that reaches these cases.
  • Once evidence exists, the branch conflicts with main in core/libs/tests/GuestWideFormatting.cpp; it needs a rebase.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 12627 core/libs/tests/GuestWideFormatting.cpp L521

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 7447 docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8417 docs/dev/debt/libc.md
PR 8965 docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9447 docs/dev/debt/libc.md
PR 9466 docs/dev/debt/libc.md
PR 9526 docs/dev/debt/libc.md
PR 10409 core/libs/tests/GuestWideFormatting.cpp
docs/dev/debt/libc.md
PR 10780 docs/dev/debt/libc.md
PR 11109 docs/dev/debt/libc.md
PR 11172 docs/dev/debt/libc.md
PR 11332 docs/dev/debt/libc.md
PR 11625 docs/dev/debt/libc.md
PR 11634 docs/dev/debt/libc.md
PR 11661 docs/dev/debt/libc.md
PR 11689 docs/dev/debt/libc.md
PR 11698 docs/dev/debt/libc.md
PR 11726 docs/dev/debt/libc.md
PR 11848 docs/dev/debt/libc.md
PR 12682 docs/dev/debt/libc.md
PR 12688 docs/dev/debt/libc.md
PR 12700 docs/dev/debt/libc.md
PR 12849 docs/dev/debt/libc.md
PR 12965 docs/dev/debt/libc.md
PR 13449 docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 14212 docs/dev/debt/libc.md
PR 15095 docs/dev/debt/libc.md
PR 17010 docs/dev/debt/libc.md
PR 17026 docs/dev/debt/libc.md
PR 18110 docs/dev/debt/libc.md
PR 18122 docs/dev/debt/libc.md
PR 18347 docs/dev/debt/libc.md
PR 18389 docs/dev/debt/libc.md
PR 18481 docs/dev/debt/libc.md
PR 18513 docs/dev/debt/libc.md
PR 18524 docs/dev/debt/libc.md
PR 18525 docs/dev/debt/libc.md

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 29, 2026
@fogydes

fogydes commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Verdict

stale+rebase

Findings

  1. [verified] Merge conflict against current origin/main (bb04a4f1ea): git merge-tree --write-tree origin/main fb98512bf7ee58032649cb02b336e5881f4a26a7 exits with code 1. The branch is 1,639 commits behind main and has a content conflict in core/libs/tests/GuestWideFormatting.cpp.
  2. [verified] Conventions check passed: python tools/check_conventions.py --base 801d5b9bc11049e6274daca09d70690bd5b8d0a9 in a scratch worktree succeeds with 0 findings and 0 errors.
  3. [read-only] Missing PR checklist line: The PR checklist omits one required template line from .github/pull_request_template.md:
    • - [ ] Fixes: <!-- issue it closes as Fixes #N, or none -->
      Per AGENTS.md, all checklist lines must be kept and answered (Fixes: none if no issue is closed).
  4. [author-reported] Measured behavior from libSceLibcInternal.sprx on PS5 firmware 12.70 for literal-text behavior on %q, %D/%O/%U, unknown conversions, and width handling; tested guest_wide_formatting on prior head 06bd246798. Not tested with title runtime libc.prx or on Windows.

Freshness envelope

  • Head: fb98512bf7ee58032649cb02b336e5881f4a26a7
  • Base: 801d5b9bc11049e6274daca09d70690bd5b8d0a9
  • Behind origin/main: 1,639 commits
  • Merge-tree: exit 1 (conflict in core/libs/tests/GuestWideFormatting.cpp)

Cross-PR ledger

  • No other open PR currently touches core/libs/prx/libc/src/FormattingWide.cpp or core/libs/tests/GuestWideFormatting.cpp.

@oneandonlydean oneandonlydean self-assigned this Oct 30, 2026
@MarcZX10
MarcZX10 force-pushed the codex/wide-printf-extensions-5293 branch from fb98512 to 6de675e Compare November 1, 2026 02:18
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 1, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

The current PR description is missing the template’s Fixes: checklist line. Please add - [x] Fixes: none, or name the issue if this closes one.

@fogydes

fogydes commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Correction: Previous review flagged verdict stale+rebase with a merge conflict on GuestWideFormatting.cpp at head dcf8dc9b38d. Head has since updated to 6de675ebf48 via rebase onto base 0e9dc7bc4c, cleanly resolving the conflict against origin/main (clean merge-tree exit 0). Verdict updates from stale+rebase to should-fix.

should-fix

Findings

  1. [verified] python tools/check_conventions.py --base 0e9dc7bc4c in scratch worktree passes cleanly with 0 errors and 0 warnings.
  2. [verified] All 8 commits in branch history are conventional and maintain a clean linear history without merge commits.
  3. [verified] PR title matches commit subjects (fix(libc): follow measured wide printf behavior).
  4. [read-only] PR description checklist is missing the required template line from .github/pull_request_template.md:
    • - [ ] Fixes: none (or issue # closed).
      As collaborator @oneandonlydean requested, please add - [x] Fixes: none to complete the checklist.
  5. [verified] No comments were added in code outside #endif / namespace ends.
  6. [author-reported] Probe on libSceLibcInternal.sprx (firmware 12.70) verified literal-text behavior for %q, %D/%O/%U, unknown conversions, and width handling in swprintf. guest_wide_formatting_tests passes 1/1.

Freshness envelope

  • Head SHA: 6de675ebf48b46bb5546a4c8a606e54ce480d08d
  • Base SHA: 0e9dc7bc4c9755c3ce803f6bbdff9dc9f25d68bb
  • Commits behind origin/main: 534
  • Commits ahead of origin/main: 8
  • git merge-tree --write-tree origin/main 6de675ebf48: clean merge (exit code 0, tree c5063219761767ae38f0452f0af0605ba9f55e74)

Cross-PR ledger

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replies checked — Fixes checklist line missing, no code finding

The PR body omits the template's Fixes: checklist line that a reviewer asked for, and the branch merges cleanly with current upstream/main.

What I ran

  • Live head: 6de675ebf48b46bb5546a4c8a606e54ce480d08d (OPEN, matches the batch file).
  • gh api comments, review comments and reviews on #5303, kept only items after 2026-10-27T00:00:07Z from users other than MarcZX10 and bots.
  • gh pr view 5303 --json body,statusCheckRollup.
  • git show 6de675ebf48b46bb5546a4c8a606e54ce480d08d:.github/pull_request_template.md.
  • git merge-tree --write-tree upstream/main 6de675ebf48b46bb5546a4c8a606e54ce480d08d (upstream/main 926f7dd492).
  • Nothing was built or run.

Results

Check Result Note
Live head matches batch OPEN
PR body vs template Fixes: line missing template line at .github/pull_request_template.md L16
merge-tree vs upstream/main exit 0 clean; 716 behind, 8 ahead
Hosted conventions SUCCESS one older run CANCELLED

Findings

  • @oneandonlydean (2026-11-01 09:52 UTC) asks for - [x] Fixes: none. Confirmed: the body's checklist has no Fixes: line. Answer: agreed, add - [x] Fixes: none (this PR closes no issue).
  • @fogydes (2026-10-29, corrected 2026-11-01 13:30 UTC) reported a merge conflict in GuestWideFormatting.cpp. Stale: the head now merges cleanly with upstream/main. No answer needed beyond the checklist.
  • @fogydes says conventions passes locally. Hosted conventions is SUCCESS at this head; the local run was not repeated.
  • @fogydes lists overlaps with #11214 and #11907 (both OPEN). Not re-run here; not verified.
  • The measured PS5 behaviour for %q, %D/%O/%U and unknown conversions is author-reported. Not verified here.

Sources

Not verified

  • The PS5 measurements and the overlap claims with #11214 and #11907.
  • The local conventions run and any build or test.

husseinkad and others added 6 commits November 5, 2026 21:15
…t in the wide printf family

The wide printf family rejected the q length modifier, the D, O and U conversions, unknown conversion characters and a format ending in a percent sign, which FreeBSD 11.4 vfwprintf formats: q is long long, D, O and U are the long forms of d, o and u, an unknown conversion character prints itself with the width and the - flag, and the format ends at a trailing percent sign. swprintf, vswprintf and wprintf now do the same; snwprintf_s keeps rejecting them.
…te pair whole as an unknown conversion

snwprintf_s accepted the q length modifier through the shared parser and now rejects it again. An unknown conversion character that is a surrogate pair is printed as one character, so the width padding no longer splits the pair.
@MarcZX10
MarcZX10 force-pushed the codex/wide-printf-extensions-5293 branch from 6de675e to 9ff570b Compare November 5, 2026 21:20
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 5, 2026
@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 9ff570b087, merged onto main 49f3653632 (db1907c817).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release.

guest_wide_formatting aborts in 3 of 3 runs:

snwprintf_s: swprintf surrogate pair as an unknown conversion
FATAL: abort() (SIGABRT)

The same test passes on main on this machine (full Windows sweep of main 988ee6d3db), so the failure comes with this PR. The branch is old, though, so it may be an interaction with later main changes rather than the PR's own code.

AI-assisted: yes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Hi @MarcZX10 @adriadam10,

guest_wide_formatting aborts on this head merged onto current main (Windows and Linux): "snwprintf_s: swprintf surrogate pair as an unknown conversion". The new surrogate cases are never reached, because the branch that prints an unknown conversion (FormattingWide.cpp, the else if (conversion == u'S' || (conversion < 0x80 && ...)) line just above your added push_back) only accepts conversion units below 0x80. A surrogate unit is above that, so it falls through to the "Unsupported format conversion" throw and swprintf returns an error.

One change fixes it. Let every unit from 0x80 up count as an unknown conversion:

} else if (conversion == u'S' || conversion >= 0x80 || !std::strchr(LibcDetail::KnownConversions, static_cast<char>(conversion))) {

With that line, and nothing else changed, the whole of guest_wide_formatting passes on Linux with this PR merged onto main (1 of 1), including the surrogate-pair, right-aligned pair and lone-surrogate cases. A first attempt that accepted only a high plus low surrogate pair fixed the pair cases but failed on the lone-surrogate case (%3\xd83d|), so the lone unit has to be accepted too.

Could one of you add it and run the test on your side? We'll re-review once it is pushed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants