fix(libc): print %p in the FreeBSD form in the Windows printf family #2693

Closed
husseinkad wants to merge 2 commits from upstream-pr/2693 into main
husseinkad commented 2026-10-10 11:02:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T11:02:14Z.


What

On Windows the guest printf family sent %p to the host CRT, which prints a zero-padded 16-digit value without a prefix: 0000000000001234 for 0x1234 and 0000000000000000 for NULL. FreeBSD's vfprintf.c (case 'p') sets ox[1] = 'x' unconditionally, so the output always has the 0x prefix, lowercase digits, and NULL prints 0x0; #, + and space are ignored, - and 0 and width and precision behave as for an integer conversion (%.0p of NULL prints 0x). The wide vfwprintf.c is identical. An existing check in core/libs/tests/Formatting.cpp compared the guest output with the host's %p and therefore encoded the old behaviour.

LibcDetail::FormatPointer (WindowsFormatting.hpp) builds that form and is used by FormatWindows (snprintf, sprintf, vsnprintf, vfprintf, printf, ...) and by FormatWide (swprintf, wprintf, ...). The Linux narrow path still goes through the host for formats without wide arguments; that is recorded in TechnicalDebt (glibc prints a null pointer as (nil)).

Tested

Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:

  • guest_formatting (Windows-only narrow %p cases: NULL, a normal value, width, -, 0, precision, %.0p, truncation return values) and guest_wide_formatting (wide cases) fail without the change and pass with it. ctest -R "formatting|guest_strings|file_streams|standard_streams" passes.
  • Outside the repo: a differential run of the built exports (snprintf, sprintf, vsnprintf, swprintf) against a reference of FreeBSD's algorithm, cross-checked against the host %#llx, over 114,336 distinct format specs (all flag subsets and orders, widths, precisions, * forms) x 8 values x buffer sizes 0 to len+7: about 2.8 million calls, 0 divergences, no va_list mutation, no guard-byte overrun.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py --branch reports no overlap.
  • Linux not 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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810709211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2693). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-10T11:02:14Z. --- ### What On Windows the guest printf family sent `%p` to the host CRT, which prints a zero-padded 16-digit value without a prefix: `0000000000001234` for 0x1234 and `0000000000000000` for NULL. FreeBSD's `vfprintf.c` (`case 'p'`) sets `ox[1] = 'x'` unconditionally, so the output always has the `0x` prefix, lowercase digits, and NULL prints `0x0`; `#`, `+` and space are ignored, `-` and `0` and width and precision behave as for an integer conversion (`%.0p` of NULL prints `0x`). The wide `vfwprintf.c` is identical. An existing check in `core/libs/tests/Formatting.cpp` compared the guest output with the host's `%p` and therefore encoded the old behaviour. `LibcDetail::FormatPointer` (`WindowsFormatting.hpp`) builds that form and is used by `FormatWindows` (snprintf, sprintf, vsnprintf, vfprintf, printf, ...) and by `FormatWide` (swprintf, wprintf, ...). The Linux narrow path still goes through the host for formats without wide arguments; that is recorded in TechnicalDebt (glibc prints a null pointer as `(nil)`). ### Tested Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release: - `guest_formatting` (Windows-only narrow `%p` cases: NULL, a normal value, width, `-`, `0`, precision, `%.0p`, truncation return values) and `guest_wide_formatting` (wide cases) fail without the change and pass with it. `ctest -R "formatting|guest_strings|file_streams|standard_streams"` passes. - Outside the repo: a differential run of the built exports (`snprintf`, `sprintf`, `vsnprintf`, `swprintf`) against a reference of FreeBSD's algorithm, cross-checked against the host `%#llx`, over 114,336 distinct format specs (all flag subsets and orders, widths, precisions, `*` forms) x 8 values x buffer sizes 0 to len+7: about 2.8 million calls, 0 divergences, no `va_list` mutation, no guard-byte overrun. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py --branch` reports no overlap. - Linux not run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 11:02:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T11:02:32Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096817294 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2693#issuecomment-6096817294). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T11:02:32Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

Pull request closed

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!2693
No description provided.