fix(libc): print 0 for %#.0o of zero on Windows #3566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3566"
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:26:52Z.
What
printf("%#.0o", 0)printed nothing on Windows. C (7.21.6.1) and FreeBSD'svfprintfprint0: foro,#raises the precision as far as needed to make the first digit a zero, and "if the value and precision are both 0, a single 0 is printed".The guest formatter (
FormatWindows) hands each conversion to the host'ssnprintf, and MinGW's prints nothing for this one. When#,o, a zero value and a precision of 0 (.0,., or.*given 0) meet, the formatter now asks the host for a precision of 1. That prints the single0and keeps the width and the other flags. Other values, precisions and conversions are unchanged;%#.0xof 0 still prints nothing, as C requires.The formatter is shared: Windows runs it for every format, Linux only for formats with a guest wide conversion (
%ls,%lc,%S,%C) and hands the rest to glibc, which already prints0.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 checks octal zero throughsprintfandvsnprintf:%#.0o,%#.oand%#.*ogiven 0; with a width, with-, and with thelandhhlengths; and in a format with%ls. It also checks that%#.0oof 8 prints010,%#.3oof 0 prints000,%#oof 0 prints0, and%.0oand%#.0xof 0 print nothing. It fails without the fix. Mutation check, all caught:#;u,xandXas well;Not run on Linux (no Linux host here); the change has no platform-specific part.
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:34:40Z.
Checked the change in
FormatWindowsagainst C 7.21.6.1 (#withoraises the precision so the first digit is 0, so value 0 with precision 0 prints0): it only fires for#,o, a zero value and precision 0 (.0,.,.*given 0), keeps width and-, and leavesx/X/uuntouched. The expected strings inguest_formattingcheck out by hand; build and ctest are green on Linux (the test passes without the change here since glibc already prints0, so the Windows result rests on your run). Merging.