fix(libc): accept printf argument positions above 99 #9552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9552"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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'svfprintfhas no such limit:int(lib/libc/stdio/vfprintf.c:563-575).__find_argumentsgrows the argument type table for any position (lib/libc/stdio/printf-pos.c:622,__grow_type_table).NL_ARGMAX99 (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.
maximumArgumentPositionis nowINT_MAX, where FreeBSD'sintposition would overflow. Position 0 and positions aboveINT_MAXstill throw.The two
libc.mdsentences that named the 99 limit (the narrow printf family and%p) now sayINT_MAX. Those are minimal edits, because #8855 rewrites the same sentences; whichever merges second keeps theINT_MAXwording.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%lspasses now: it moves from the invalid-position list to a passing check with 121 arguments,"%120$d|%1$d|%100$d|%121$ls", which gives120|1|100|x.%2147483648$d%ls(aboveINT_MAX) joins the list, which keeps%0$d%lsand%*0$d%ls.Results:
guest_formattingandguest_wide_formattingpass. The 19 tests matching format, printf, scanf,guest_crtand libc all pass.guest_formattingaborts withFormat argument position out of range.tools/check_conventions.pyreports 0 errors. Its one warning is about the length of the%pdebt entry, which was already over 1000 characters onmain(1237); this change only touches it, and shortening it belongs to #8855's rewrite.tools/pr_overlap.py --branchoverlaps with #8855 ondocs/dev/debt/libc.mdlines 110-112, as described above.git merge-treeagainst #3987, #9087 and #9527, which also editWindowsFormatting.hpp, is clean.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)libc.mdsentence changes)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 onif either must land first), preserving both debt updates. Second, this branch is based on8c26eac3, 23 commits behind current maindce41a89478876a8e3ea9c346b1dac00bb31c8cd; 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.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 ontomain; its merge-base is8c26eac3c).ctest -R '^guest_formatting$'passes 3 of 3.libc/include/WindowsFormatting.hpprestored to the merge-base (the PR's tests kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
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
cfada08f98intomaind6732b51a6(8238956f91). It merged cleanly; git auto-mergeddocs/dev/debt/libc.md.guest_formattingandguest_wide_formattingpass. These include the new 121-argument%120$d|%1$d|%100$d|%121$lscheck and the%2147483648$d%lsrejection.Not repeated here: your negative control with the cap back at 99.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:47:59Z.
Thanks @MarcZX10. Merged current
main(d6eafa54d0) in a new merge commit314c7c4b9c(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
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
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 based6eafa54d). 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 samedocs/dev/debt/libc.mdparagraph; please agree the merge order with that author, preserve both text changes, and recordDepends onif 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.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 based6eafa54d) and rerun focused formatting tests; and record merge-order agreement with newly open #9699, which touches the samedocs/dev/debt/libc.mdparagraph, 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