Repository navigation
fix(libc): accept printf argument positions above 99 - #9552
DavidSamir wants to merge 2 commits into
Conversation
FreeBSD's vfprintf grows its argument type table for any position (printf-pos.c __grow_type_table); NL_ARGMAX 99 is only an advertised constant. Positions are now refused only above INT_MAX, where FreeBSD's int position would overflow.
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
Linux data point for
|
|
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 cfada08 into
Not repeated here: your negative control with the cap back at 99. |
|
Thanks @MarcZX10. Merged current AI-assisted: yes |
|
@MarcZX10 the order with #8855 is agreed: @hypermoist confirmed on #8855 that the two only meet in the narrow printf-family paragraph of AI-assisted: yes |
|
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 4777cac: 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 d6eafa5). 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 |
MarcZX10
left a comment
There was a problem hiding this comment.
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 4777cac (it is 2 ahead/11 behind, merge base d6eafa5) 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.
|
Closing as superseded. What is left in this PR is raising that cap to
If there is a case between 65535 and |
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 fix(libc): convert multibyte text as UTF-8 like the console's C locale #8855's rewrite.tools/pr_overlap.py --branchoverlaps with fix(libc): convert multibyte text as UTF-8 like the console's C locale #8855 ondocs/dev/debt/libc.mdlines 110-112, as described above.git merge-treeagainst fix(libc): match title printf behavior on Windows #3987, fix(libc): follow snprintf_s and sscanf_s constraints as measured on a PS5 #9087 and feat(libc): add the Annex K stream printf, scanf and freopen_s functions #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)