fix(libc): accept printf argument positions above 99 #9552

Closed
DavidSamir wants to merge 2 commits from upstream-pr/9552 into main
DavidSamir commented 2026-10-22 02:04:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:04:41Z.


What

The guest printf formatter (WindowsFormatting.hpp, used by the narrow and wide printf families whenever a format needs the guest formatter) threw for any argument position above 99, such as %100$d. FreeBSD 11's vfprintf has no such limit:

  • The position: it is parsed as a plain int (lib/libc/stdio/vfprintf.c:563-575).
  • The table: __find_arguments grows the argument type table for any position (lib/libc/stdio/printf-pos.c:622, __grow_type_table).
  • NL_ARGMAX 99 (include/limits.h:123) is only the advertised minimum; nothing enforces it.

Here the argument table is already a growable vector, so the cap was the only limit. maximumArgumentPosition is now INT_MAX, where FreeBSD's int position would overflow. Position 0 and positions above INT_MAX still throw.

The two libc.md sentences that named the 99 limit (the narrow printf family and %p) now say INT_MAX. Those are minimal edits, because #8855 rewrites the same sentences; whichever merges second keeps the INT_MAX wording.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is CPU-side, so no GPU is involved.

guest_formatting (core/libs/tests/Formatting.cpp) changes:

  • %100$d%ls passes now: it moves from the invalid-position list to a passing check with 121 arguments, "%120$d|%1$d|%100$d|%121$ls", which gives 120|1|100|x.
  • A new invalid case: %2147483648$d%ls (above INT_MAX) joins the list, which keeps %0$d%ls and %*0$d%ls.

Results:

  • guest_formatting and guest_wide_formatting pass. The 19 tests matching format, printf, scanf, guest_crt and libc all pass.
  • Negative control: with the cap back at 99, guest_formatting aborts with Format argument position out of range.
  • tools/check_conventions.py reports 0 errors. Its one warning is about the length of the %p debt entry, which was already over 1000 characters on main (1237); this change only touches it, and shortening it belongs to #8855's rewrite.
  • tools/pr_overlap.py --branch overlaps with #8855 on docs/dev/debt/libc.md lines 110-112, as described above. git merge-tree against #3987, #9087 and #9527, which also edit WindowsFormatting.hpp, is clean.

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 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
  • Generic behaviour, not specific to one title
  • Depends on: none (order with #8855 agreed with its author: neither waits; whichever merges second keeps both libc.md sentence changes)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4960992622 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T02:04:41Z. --- ### What The guest printf formatter (`WindowsFormatting.hpp`, used by the narrow and wide printf families whenever a format needs the guest formatter) threw for any argument position above 99, such as `%100$d`. FreeBSD 11's `vfprintf` has no such limit: - **The position:** it is parsed as a plain `int` (`lib/libc/stdio/vfprintf.c:563-575`). - **The table:** `__find_arguments` grows the argument type table for any position (`lib/libc/stdio/printf-pos.c:622`, `__grow_type_table`). - **`NL_ARGMAX` 99** (`include/limits.h:123`) is only the advertised minimum; nothing enforces it. Here the argument table is already a growable vector, so the cap was the only limit. `maximumArgumentPosition` is now `INT_MAX`, where FreeBSD's `int` position would overflow. Position 0 and positions above `INT_MAX` still throw. The two `libc.md` sentences that named the 99 limit (the narrow printf family and `%p`) now say `INT_MAX`. Those are minimal edits, because #8855 rewrites the same sentences; whichever merges second keeps the `INT_MAX` wording. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is CPU-side, so no GPU is involved. `guest_formatting` (`core/libs/tests/Formatting.cpp`) changes: - **`%100$d%ls` passes now:** it moves from the invalid-position list to a passing check with 121 arguments, `"%120$d|%1$d|%100$d|%121$ls"`, which gives `120|1|100|x`. - **A new invalid case:** `%2147483648$d%ls` (above `INT_MAX`) joins the list, which keeps `%0$d%ls` and `%*0$d%ls`. Results: - `guest_formatting` and `guest_wide_formatting` pass. The 19 tests matching format, printf, scanf, `guest_crt` and libc all pass. - Negative control: with the cap back at 99, `guest_formatting` aborts with `Format argument position out of range`. - `tools/check_conventions.py` reports 0 errors. Its one warning is about the length of the `%p` debt entry, which was already over 1000 characters on `main` (1237); this change only touches it, and shortening it belongs to #8855's rewrite. - `tools/pr_overlap.py --branch` overlaps with #8855 on `docs/dev/debt/libc.md` lines 110-112, as described above. `git merge-tree` against #3987, #9087 and #9527, which also edit `WindowsFormatting.hpp`, is clean. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none (order with #8855 agreed with its author: neither waits; whichever merges second keeps both `libc.md` sentence changes) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 04:15:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:15:35Z.

Review: CHANGES_REQUESTED


The parser bound now matches FreeBSD’s signed-int position domain, and the 121-argument positive case plus above-INT_MAX negative case exercise the stated behavior. There are two repository-process items before approval. First, #8855 is still open and edits the same debt sentences; “whichever merges second” does not record author agreement/order. Please coordinate with #8855’s author and state the agreed order (and Depends on if either must land first), preserving both debt updates. Second, this branch is based on 8c26eac3, 23 commits behind current main dce41a89478876a8e3ea9c346b1dac00bb31c8cd; please update and rerun the focused formatting tests and checks on the updated head. Hosted eligibility, conventions, intake, labels and report checks pass; relinker matrix passes and Linux/Windows product jobs are skipped. Windows results are author-reported; I did not run tests locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609188409 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#pullrequestreview-5609188409). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:15:35Z. **Review:** CHANGES_REQUESTED --- The parser bound now matches FreeBSD’s signed-int position domain, and the 121-argument positive case plus above-INT_MAX negative case exercise the stated behavior. There are two repository-process items before approval. First, #8855 is still open and edits the same debt sentences; “whichever merges second” does not record author agreement/order. Please coordinate with #8855’s author and state the agreed order (and `Depends on` if either must land first), preserving both debt updates. Second, this branch is based on `8c26eac3`, 23 commits behind current main `dce41a89478876a8e3ea9c346b1dac00bb31c8cd`; please update and rerun the focused formatting tests and checks on the updated head. Hosted eligibility, conventions, intake, labels and report checks pass; relinker matrix passes and Linux/Windows product jobs are skipped. Windows results are author-reported; I did not run tests locally.
xXPBSXx commented 2026-10-22 04:42:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:42:38Z.


Linux data point for cfada08f98: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is 8c26eac3c).

  • With the PR: ctest -R '^guest_formatting$' passes 3 of 3.
  • With libc/include/WindowsFormatting.hpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332892012 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#issuecomment-6332892012). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:42:38Z. --- Linux data point for `cfada08f98`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `8c26eac3c`). - With the PR: `ctest -R '^guest_formatting$'` passes 3 of 3. - With `libc/include/WindowsFormatting.hpp` restored to the merge-base (the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
JJenkx commented 2026-10-22 06:16:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T06:16:50Z.


Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release. I tested a local merge of your head cfada08f98 into main d6732b51a6 (8238956f91). It merged cleanly; git auto-merged docs/dev/debt/libc.md.

  • guest_formatting and guest_wide_formatting pass. These include the new 121-argument %120$d|%1$d|%100$d|%121$ls check and the %2147483648$d%ls rejection.
  • The whole libc suite passes: 143/143.

Not repeated here: your negative control with the cap back at 99.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334156914 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#issuecomment-6334156914). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-22T06:16:50Z. --- Independent Windows run of this PR, as data only. The machine is a Ryzen 9 5950X on Windows 11 (10.0.22621), built with WinLibs GCC 15.2.0 UCRT r7, Release. I tested a local merge of your head cfada08f98 into `main` d6732b51a6 (8238956f91). It merged cleanly; git auto-merged `docs/dev/debt/libc.md`. - `guest_formatting` and `guest_wide_formatting` pass. These include the new 121-argument `%120$d|%1$d|%100$d|%121$ls` check and the `%2147483648$d%ls` rejection. - The whole libc suite passes: 143/143. Not repeated here: your negative control with the cap back at 99.
DavidSamir commented 2026-10-22 08:47:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:47:59Z.


Thanks @MarcZX10. Merged current main (d6eafa54d0) in a new merge commit 314c7c4b9c (no force-push); it merged cleanly. Rerun on that head (Windows 11, WinLibs GCC 15.2): guest_formatting and guest_wide_formatting pass; check_conventions.py reports 0 errors (its one warning is a libc debt entry already 1238 characters on main).

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336673897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#issuecomment-6336673897). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T08:47:59Z. --- Thanks @MarcZX10. Merged current `main` (`d6eafa54d0`) in a new merge commit `314c7c4b9c` (no force-push); it merged cleanly. Rerun on that head (Windows 11, WinLibs GCC 15.2): guest_formatting and guest_wide_formatting pass; check_conventions.py reports 0 errors (its one warning is a libc debt entry already 1238 characters on main). AI-assisted: yes
DavidSamir commented 2026-10-22 09:20:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:20:39Z.


@MarcZX10 the order with #8855 is agreed: @hypermoist confirmed on #8855 that the two only meet in the narrow printf-family paragraph of docs/dev/debt/libc.md, neither depends on the other, and whichever merges second keeps both sentence changes. It's now recorded in the checklist.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337295672 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#issuecomment-6337295672). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T09:20:39Z. --- @MarcZX10 the order with #8855 is agreed: @hypermoist confirmed on #8855 that the two only meet in the narrow printf-family paragraph of `docs/dev/debt/libc.md`, neither depends on the other, and whichever merges second keeps both sentence changes. It's now recorded in the checklist. AI-assisted: yes
MarcZX10 commented 2026-10-22 11:25:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:25:42Z.


The previously open merge-order point with #8855 is now resolved in the checklist, and the Windows/Linux test evidence is strong (including an independent Windows libc suite run). I refreshed the checks against current upstream/main 4777caca34: diff-check passes, conventions has 0 errors with the existing long-debt warning, merge-tree is clean, but this branch is 2 ahead/11 behind (merge base d6eafa54d). Please update to current main and rerun the focused formatting tests/checks before merge. The current overlap bot also identifies newly open #9699 touching the same docs/dev/debt/libc.md paragraph; please agree the merge order with that author, preserve both text changes, and record Depends on if either PR must land first. The formatter behavior appears separate. Product builds remain skipped in hosted CI; I did not run C++ tests locally because the filesystem is full.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339578462 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#issuecomment-6339578462). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:25:42Z. --- The previously open merge-order point with #8855 is now resolved in the checklist, and the Windows/Linux test evidence is strong (including an independent Windows libc suite run). I refreshed the checks against current upstream/main 4777caca34: diff-check passes, conventions has 0 errors with the existing long-debt warning, merge-tree is clean, but this branch is 2 ahead/11 behind (merge base d6eafa54d). Please update to current main and rerun the focused formatting tests/checks before merge. The current overlap bot also identifies newly open #9699 touching the same `docs/dev/debt/libc.md` paragraph; please agree the merge order with that author, preserve both text changes, and record `Depends on` if either PR must land first. The formatter behavior appears separate. Product builds remain skipped in hosted CI; I did not run C++ tests locally because the filesystem is full.
MarcZX10 commented 2026-10-22 11:25:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T11:25:43Z.

Review: CHANGES_REQUESTED


The formatter change has good focused and independent Windows/Linux evidence, and the #8855 coordination is now recorded. Two repository requirements remain: update this branch from current upstream/main 4777caca34 (it is 2 ahead/11 behind, merge base d6eafa54d) and rerun focused formatting tests; and record merge-order agreement with newly open #9699, which touches the same docs/dev/debt/libc.md paragraph, adding Depends on if sequencing is required. Current diff-check and conventions pass (0 errors; one inherited debt-length warning), and merge-tree is clean. Product Linux/Windows jobs are skipped; I did not run C++ tests locally due to a full filesystem.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5613409075 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9552#pullrequestreview-5613409075). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T11:25:43Z. **Review:** CHANGES_REQUESTED --- The formatter change has good focused and independent Windows/Linux evidence, and the #8855 coordination is now recorded. Two repository requirements remain: update this branch from current upstream/main 4777caca34 (it is 2 ahead/11 behind, merge base d6eafa54d) and rerun focused formatting tests; and record merge-order agreement with newly open #9699, which touches the same `docs/dev/debt/libc.md` paragraph, adding Depends on if sequencing is required. Current diff-check and conventions pass (0 errors; one inherited debt-length warning), and merge-tree is clean. Product Linux/Windows jobs are skipped; I did not run C++ tests locally due to a full filesystem.

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