fix(libc): ignore printf length modifiers that do not apply, as titles' libc.prx does #11893
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11893"
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 JJenkx on 2026-10-27T11:55:46Z.
What
The printf family throws when a length modifier does not apply to its conversion, which aborts the title. The wide family returns -1 instead.
mainthrows "Invalid integer length" for%Ld, "Unsupported format conversion" for%hhc,%Ls,%Lcand%hp, and "Invalid floating length" for%hfor%zg.The
libc.prxthat titles ship ignores such a modifier and formats the conversion as if it were absent:maind i o u x XL(formats anint)%Ldof0x89abcdefgives-1985229329nL(writes anint)a%Lnstores 1 in the low 32 bitsc,sl%hhc%Lc%zcgivesDEF,%hhsgives the narrow stringa e f g(and upper case)L%hf,%llfgive1.500000,%jagives0x1.8p+0p%hp,%Lpgive1234Width, precision and flags still apply:
[%5Ld][%-8.3Lx]gives[1094861636][41424344].A new
LibcDetail::ApplicableLengthdrops the modifier inFormatWindowsand in the wide formatter. On Linux,RequiresGuestFormattingsends a format with such a modifier to the guest formatter, because glibc reads%Ldaslong long. The_sforms are unmeasured and still throw; a new debt entry records that.Tested
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,main8ff4baf534.libc.prxof PPSA07923 and PPSA13934 natively, with one process per format.snprintf:Lond i u x X oandn;h hh l ll j z t Loncands;h hh ll j z t l Lonf, andhorzone,ganda;h hh ll L zonp;n.swprintf:%Ld %Lx %hf %zg %hp %Lp %hhc %Lc %hhs %Ls %hs %Ln.hh h l ll j z ton integers,loncands), the results matchmain. The unknown modifiers%qd,%I64dand%wdprint as text on both.snprintfandswprintfwith the same arguments.guest_formatting: the newCheckIgnoredLengthscovers every row of the table.guest_wide_formatting:%Lnnow expects the count written as anint, as the titles'swprintfdoes; before, it expected -1.%Ld|%Lx|%hf|%zg|%hp|%Lc.[%lp], which an existing check expected to be refused, now expects[1234]. The titles'swprintfprints%lp,%llpand%hpas1234.guest_formatting,guest_wide_formattingandguest_stdio_variadicpass in three runs out of three on the exact head17c950f0a5. That commit passesintarguments to%Ldand anintwith a guard to%Ln, per review; the first head4630a53d0ealso passed 3/3.guest_formattingandguest_wide_formattingat4630a53d0e(comment), and MarcZX10's 3/3 of the three groups at #11907's head15b33e8e76, whose parent is17c950f0a5.main'sWindowsFormatting.hpp,Formatting.cppandFormattingWide.cppand these tests,guest_formattingandguest_wide_formattingabort (exit 0xc0000409).python tools/check_conventions.py --base origin/mainandgit diff --checkpass._sforms.%Lfwith adoubleargument is mismatched arguments and is not covered.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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T12:02:01Z.
Review: DISMISSED
The formatting changes have useful title measurements and broad Windows coverage, but the new regression tests pass argument types that do not match the behavior the formatter now implements, so their results are undefined and may vary across compilers/ABIs.
Formatting.cpp:81,%Ldis normalized to%d, andFormatWindowsthen retrieves anint(args.Next<int>()atWindowsFormatting.hpp:645). The test passes0x89abcdefu, anunsigned intvalue not representable asint. Please pass anintvalue for%Ld(while keeping the%Lx/%Lu/%Loarguments unsigned).Formatting.cpp:87-88,%Lnis normalized to%n, which retrieves and writes anint*; the test passes along long*and reads the modifiedlong long. Please use anintcount with an adjacent guard field if the test needs to prove only theintbytes were written.After correcting those cases, please run the focused formatting tests on Linux as well.
Formatting.cppchanges Linux'sRequiresGuestFormattingrouting, and the PR currently says that path was not tested. The Windows title measurements do not exercise that routing.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T00:17:42Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The test argument-type fixes are present, and #11907's descendant run covers this exact source head, but #11893 is still based on an older
main.What I ran
Reviewed head
17c950f0a54f8e44ec1e7561034ab6d7086ef824; its merge base with currentmainis8ff4baf53489033dae79090640143e82d159ee4d. The current-main preview is clean, butdocs/dev/debt/libc.mdchanged on both sides. I inspected the corrected%Ldand%Lntest changes. Environment: Linux x86-64, Git and GitHub CLI. I did not build or run tests locally.Results
docs/dev/debt/libc.md%Ldtest passes anint; the%Lntest writes into guardedintstorageCommand output
Negative control
%Ldand%Lntests validate the actual argument types and write widthFindings
Blocking
8ff4baf534, not currentmain3a2b91981651. The merge preview is clean, but the contribution rules require keeping the branch current. Rebase and rerun the focused tests on that base before approval.Non-blocking
Sources
Not verified
To get this to a good state
Rebase onto current
main, preserve the updated debt wording, and rerunguest_formattingandguest_wide_formattingon the new head. Record the exact head/base; I will re-check and rerun the focused tests available here.