fix(libc): format positional arguments on Windows #3569
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3569"
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 DariusHQ on 2026-10-11T13:27:10Z.
What
The guest formatter (
FormatWindows) threwUnsupported format conversionon positional arguments (%n$and*m$), which FreeBSD'svfprintfand glibc accept. Windows runs it for every format, soprintf("%2$s %1$d", 7, "x")from a title aborted there while Linux handed the same format to glibc. Linux runs it for formats with a guest wide conversion (%ls,%lc,%S,%C), so a positional format with one of those threw on both.When a format names a position, the formatter now scans it first, as FreeBSD's
__find_argumentsdoes. Each argument up to the highest position gets the type its conversions give it: an integer or pointer, adouble, or along doubleforL. The formatter reads them from the guestva_listin that order into a table and formats from the table. Where POSIX leaves the result undefined, it follows FreeBSD:%2$d %dtakes 2 then 3;*m$does not move that position;int.POSIX allows positions 1 to
NL_ARGMAX, which is 99 on FreeBSD. 0 and anything above 99 throw, so a malformed format cannot make the formatter read an arbitrarily long table off the guest stack. TechnicalDebt lists that limit where it listed positional arguments.Formats without a position are formatted as before.
Tested
Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with
BUILD_TESTING=ONonmaina11c8f7f7with four branches merged together: this one and the%#.0o,'flag, positional-argument andsendfilebranches opened alongside it:ctest833/837 passed. The four failures fail the same way onmainhere:windows_exceptions(#3411);guest_kernel_sys:symlinkthrowsFunction not implementedon Windows, which #3510 addresses;guest_filesystem: restoring the directory time fails on Windows, which #3518 addresses;agc_driver_emulated_color_compare: the GPU here cannot sample the sRGB image it uses.guest_formattingnow runs the positional check that was Linux-only (%%ls:%2$d:%1$d) on Windows too, and new checks throughsprintf,snprintfandvsnprintf:int,hh,double,long doubleandchar*arguments out of order;intarguments in reverse, past the registers into the stack area;doublearguments and anintin reverse;%lsand%Cby position;%lsso that Linux formats them the same way;Mutation check, all caught:
*m$moving the position;Lread asdouble;*m$positions left out of the scan, or not making the format positional;%n$ignored while formatting;long doubleordoublearguments read as integers;Not run on Linux (no Linux host here). The change has no platform-specific part, and the new checks without a wide conversion expect what glibc prints.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:40:49Z.
Checked the positional-argument scan against POSIX/FreeBSD
__find_arguments(argument classes,NL_ARGMAX99, undefined cases following FreeBSD), built and ranguest_formattingandguest_wide_formattingon Linux (the new checks fail without the change) and read the TechnicalDebt update; merging once #3567 is in.