Repository navigation
fix(libc): format positional arguments on Windows - #3569
Merged
adriadam10 merged 2 commits intoOct 11, 2026
Merged
Conversation
FreeBSD's vfprintf takes ' as the thousands-grouping flag. The Windows formatter threw on it as an unsupported conversion. The guest's setlocale only accepts the C locale, which has no thousands separator, so the flag changes nothing: it is dropped before the host's printf sees it, and the host's locale cannot add separators.
The guest formatter threw on %n$ and *m$, which FreeBSD's vfprintf and glibc accept. It now reads the arguments a numbered format names into a table first, with the types their conversions give them, and follows FreeBSD's rules for unnumbered conversions and unnamed arguments.
This was referenced Oct 11, 2026
9 tasks done
Collaborator
|
Checked the positional-argument scan against POSIX/FreeBSD |
12 tasks done
10 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(Windows: windows_exceptions fails since #1423, unwinding through runtime DLL frames (std::call_once) no longer reaches the catch #3411);guest_kernel_sys:symlinkthrowsFunction not implementedon Windows, which fix(libkernel_sys): create symlinks with CreateSymbolicLinkW on Windows #3510 addresses;guest_filesystem: restoring the directory time fails on Windows, which test(libkernel): don't require restoring the directory time on Windows #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)