fix(libc): print 0 for %#.0o of zero on Windows #3566

Merged
DariusHQ merged 1 commit from upstream-pr/3566 into main 2026-10-11 21:34:44 +00:00
DariusHQ commented 2026-10-11 13:26:52 +00:00 (Migrated from github.com)

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's vfprintf print 0: for o, # 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's snprintf, 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 single 0 and keeps the width and the other flags. Other values, precisions and conversions are unchanged; %#.0x of 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 prints 0.

Tested

Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with BUILD_TESTING=ON on main a11c8f7f7 with four branches merged together: this one and the %#.0o, ' flag, positional-argument and sendfile branches opened alongside it: ctest 833/837 passed. The four failures fail the same way on main here:

  • windows_exceptions (#3411);
  • guest_kernel_sys: symlink throws Function not implemented on 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_formatting now checks octal zero through sprintf and vsnprintf: %#.0o, %#.o and %#.*o given 0; with a width, with -, and with the l and hh lengths; and in a format with %ls. It also checks that %#.0o of 8 prints 010, %#.3o of 0 prints 000, %#o of 0 prints 0, and %.0o and %#.0x of 0 print nothing. It fails without the fix. Mutation check, all caught:

  • applying the change without #;
  • applying it to u, x and X as well;
  • applying it at any precision.

Not run on Linux (no Linux host here); the change has no platform-specific part.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4819394961 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3566). Originally posted by [DariusHQ](https://github.com/DariusHQ) on 2026-10-11T13:26:52Z. --- ### What `printf("%#.0o", 0)` printed nothing on Windows. C (7.21.6.1) and FreeBSD's `vfprintf` print `0`: for `o`, `#` 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's `snprintf`, 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 single `0` and keeps the width and the other flags. Other values, precisions and conversions are unchanged; `%#.0x` of 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 prints `0`. ### Tested Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with `BUILD_TESTING=ON` on `main` `a11c8f7f7` with four branches merged together: this one and the `%#.0o`, `'` flag, positional-argument and `sendfile` branches opened alongside it: `ctest` 833/837 passed. The four failures fail the same way on `main` here: - `windows_exceptions` (#3411); - `guest_kernel_sys`: `symlink` throws `Function not implemented` on 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_formatting` now checks octal zero through `sprintf` and `vsnprintf`: `%#.0o`, `%#.o` and `%#.*o` given 0; with a width, with `-`, and with the `l` and `hh` lengths; and in a format with `%ls`. It also checks that `%#.0o` of 8 prints `010`, `%#.3o` of 0 prints `000`, `%#o` of 0 prints `0`, and `%.0o` and `%#.0x` of 0 print nothing. It fails without the fix. Mutation check, all caught: - applying the change without `#`; - applying it to `u`, `x` and `X` as well; - applying it at any precision. Not run on Linux (no Linux host here); the change has no platform-specific part. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
adriadam10 commented 2026-10-11 21:34:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:34:40Z.


Checked the change in FormatWindows against C 7.21.6.1 (# with o raises the precision so the first digit is 0, so value 0 with precision 0 prints 0): it only fires for #, o, a zero value and precision 0 (.0, ., .* given 0), keeps width and -, and leaves x/X/u untouched. The expected strings in guest_formatting check out by hand; build and ctest are green on Linux (the test passes without the change here since glibc already prints 0, so the Windows result rests on your run). Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114028103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3566#issuecomment-6114028103). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:34:40Z. --- Checked the change in `FormatWindows` against C 7.21.6.1 (`#` with `o` raises the precision so the first digit is 0, so value 0 with precision 0 prints `0`): it only fires for `#`, `o`, a zero value and precision 0 (`.0`, `.`, `.*` given 0), keeps width and `-`, and leaves `x`/`X`/`u` untouched. The expected strings in `guest_formatting` check out by hand; build and ctest are green on Linux (the test passes without the change here since glibc already prints `0`, so the Windows result rests on your run). Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3566
No description provided.