Skip to content

fix(libc): support FreeBSD wide printf conversions - #5303

Open
MarcZX10 wants to merge 3 commits into
boykopovar:mainfrom
MarcZX10:codex/wide-printf-extensions-5293
Open

MarcZX10 wants to merge 3 commits into
boykopovar:mainfrom
MarcZX10:codex/wide-printf-extensions-5293

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

Fixes #5293. The wide printf family now accepts FreeBSD's q length modifier and %D, %O, and %U conversions, prints unknown conversion characters with their width, and stops cleanly at a trailing %. The secure snwprintf_s path continues rejecting these extensions. The tests cover surrogate-pair and lone-surrogate conversion characters as well.

The two upstream implementation commits retain Hussein Kadhim as their author. A separate test-placement commit is authored by MarcZX100.

Tested

  • Debian 12, Linux x86_64, GCC 12.2: guest_wide_formatting and guest_formatting passed (2/2).
  • Conventions check and git diff --check passed.
  • The issue report includes Windows builds and FreeBSD differential testing; no Windows or FreeBSD local run.

Checklist

  • Based on current main; no other open PR implements the same 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

husseinkad and others added 3 commits October 13, 2026 16:42
…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.
@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.

@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

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 3965 docs/dev/debt/libc.md
PR 5021 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestWideFormatting.cpp
PR 6226 docs/dev/debt/libc.md
PR 6334 docs/dev/debt/libc.md
PR 6345 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6541 docs/dev/debt/libc.md
PR 6565 docs/dev/debt/libc.md
PR 6610 docs/dev/debt/libc.md
PR 6686 docs/dev/debt/libc.md
PR 6707 docs/dev/debt/libc.md
PR 6713 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 6842 docs/dev/debt/libc.md
PR 6975 docs/dev/debt/libc.md
PR 6985 docs/dev/debt/libc.md
PR 7039 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7332 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7411 docs/dev/debt/libc.md
PR 7417 docs/dev/debt/libc.md
PR 7447 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7506 docs/dev/debt/libc.md
PR 7525 docs/dev/debt/libc.md
PR 7529 docs/dev/debt/libc.md
PR 7544 docs/dev/debt/libc.md
PR 7545 docs/dev/debt/libc.md
PR 7546 docs/dev/debt/libc.md
PR 7634 docs/dev/debt/libc.md
PR 7648 docs/dev/debt/libc.md

@MarcZX10

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed blocking review. I have no new title trace or Dinkumware _Printf evidence, so the current FreeBSD/Linux results still do not justify claiming console behavior. I’ll leave the PR unrebased until that evidence exists; the relevant _Printf branches or a title reaching these conversions remain the needed next step.

This branch has not been deployed

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

Labels

docs fix error Closes an issue (Fixes #N) libc needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: the wide printf family aborts on %qd, %D, %O, %U, unknown conversions and a trailing % that FreeBSD formats; fix branch ready

4 participants