fix(libc): match reported wide scanf edge cases #9331

Merged
MarcZX10 merged 3 commits from upstream-pr/9331 into main 2026-10-22 18:36:36 +00:00
MarcZX10 commented 2026-10-21 18:39:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T18:39:21Z.


What

Implements two of the reported wide-scanner differences in #9321, based on the console scanner behavior reported in merged #8479: an incomplete floating-point exponent such as 1e+ converts its mantissa, and a format literal at end-of-input returns the assignment count (zero when nothing was assigned) instead of EOF. Adds regressions for sized and unsized buffer scans and the stream scanner.

The reported short %c field behavior is not included: #9321 asks to confirm its return count, partial-output extent and precedence first. The libc debt entry records that remaining gap. This pull request does not close #9321.

Tested

Linux x86-64, Debian GCC 12.2, Release. Configured with cmake -S . -B build -G Ninja -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DANYPS5_USE_SYSTEM_DEPS=OFF; built guest_wide_conversion_tests and guest_wide_stream_scan_tests; CTest passed guest_wide_conversion and guest_wide_stream_scan (2/2). No PS5 runtime or hardware test was performed.

python3 tools/check_conventions.py --base upstream/main reports zero errors and one debt-length warning on the existing libc scanner entry. The required local origin/main reference is 10,325 commits behind upstream; checking against it reports unrelated historical findings outside this change. tools/pr_overlap.py reports dependencies listed below.

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 under Silent stubs in their library's technical debt file
  • 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: #8306, #9087, #6044
  • Fixes: none (the follow-up addresses two reported cases; #9321 remains open)
  • Unblocks: none
  • GPUs tested: n/a (CPU-only change)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4956562850 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9331). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T18:39:21Z. --- ### What Implements two of the reported wide-scanner differences in #9321, based on the console scanner behavior reported in merged #8479: an incomplete floating-point exponent such as `1e+` converts its mantissa, and a format literal at end-of-input returns the assignment count (zero when nothing was assigned) instead of `EOF`. Adds regressions for sized and unsized buffer scans and the stream scanner. The reported short `%c` field behavior is not included: #9321 asks to confirm its return count, partial-output extent and precedence first. The libc debt entry records that remaining gap. This pull request does not close #9321. ### Tested Linux x86-64, Debian GCC 12.2, Release. Configured with `cmake -S . -B build -G Ninja -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release -DANYPS5_USE_SYSTEM_DEPS=OFF`; built `guest_wide_conversion_tests` and `guest_wide_stream_scan_tests`; CTest passed `guest_wide_conversion` and `guest_wide_stream_scan` (2/2). No PS5 runtime or hardware test was performed. `python3 tools/check_conventions.py --base upstream/main` reports zero errors and one debt-length warning on the existing libc scanner entry. The required local `origin/main` reference is 10,325 commits behind upstream; checking against it reports unrelated historical findings outside this change. `tools/pr_overlap.py` reports dependencies listed below. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #8306, #9087, #6044 - [x] Fixes: none (the follow-up addresses two reported cases; #9321 remains open) - [x] Unblocks: none - [x] GPUs tested: n/a (CPU-only change) - [x] AI-assisted: yes
wachi35676 commented 2026-10-21 23:39:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:39:55Z.


Windows run, the platform the description doesn't list, plus a wider set of inputs compared with main and with FreeBSD 11.4.

Head c092916666 merged onto main a6dcea927 (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON.

  • guest_wide_conversion, guest_wide_stream_scan, guest_scan_count, guest_wide_formatting, guest_stdio_variadic, guest_wide_string: 6/6, 3 runs.
  • Negative control: with ScanningWide.cpp from main, guest_wide_conversion fails and guest_wide_stream_scan aborts (0xc0000409).
  • check_conventions.py: one warning, debt-length on docs/dev/debt/libc.md:128.

swscanf with %lf (destination -99), main → PR:

  • 1e+, 1e, 1e-, 1e+x, 1ex, 0x1p, 0x1p+: 0 → 1, value 1. 1.5e: 0 → 1, value 1.5.
  • -, ., e5, in, nan(, 0x: 0 on both. 1e+5, inf: 1 on both.

So the change is not limited to 1e+: every field ending in an exponent marker or sign now converts its mantissa, including 1e, 1ex and hex 0x1p. The updated debt entry says "other incomplete exponent forms are not separately verified", but their behaviour changes too. FreeBSD 11.4's parsefloat also commits to the last valid prefix, so it gives 1 for all of these.

Literals, main → PR:

  • ""/x, ""/ x, ""/x%d, ""/%%: -1 → 0.
  • x/x%d: -1 on both. /x: 0 on both. a/b: 0 on both. 5/%dx: 1 on both.

For a literal that meets end of input, FreeBSD 11.4's vfwscanf goes to input_failure and returns EOF when nothing was converted (vfwscanf.c L490-L495, L783-L784). C11 7.29.2.2 also calls running out of input an input failure. So the new 0 rests only on the firmware result reported in #8479; neither FreeBSD nor the standard supports it. The %% case changes too, so it would help to say whether #8479 covered %%.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329015283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9331#issuecomment-6329015283). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:39:55Z. --- Windows run, the platform the description doesn't list, plus a wider set of inputs compared with main and with FreeBSD 11.4. Head `c092916666` merged onto main `a6dcea927` (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, `BUILD_TESTING=ON`. - `guest_wide_conversion`, `guest_wide_stream_scan`, `guest_scan_count`, `guest_wide_formatting`, `guest_stdio_variadic`, `guest_wide_string`: 6/6, 3 runs. - Negative control: with `ScanningWide.cpp` from main, `guest_wide_conversion` fails and `guest_wide_stream_scan` aborts (`0xc0000409`). - `check_conventions.py`: one warning, `debt-length` on `docs/dev/debt/libc.md:128`. `swscanf` with `%lf` (destination -99), main → PR: - `1e+`, `1e`, `1e-`, `1e+x`, `1ex`, `0x1p`, `0x1p+`: 0 → 1, value 1. `1.5e`: 0 → 1, value 1.5. - `-`, `.`, `e5`, `in`, `nan(`, `0x`: 0 on both. `1e+5`, `inf`: 1 on both. So the change is not limited to `1e+`: every field ending in an exponent marker or sign now converts its mantissa, including `1e`, `1ex` and hex `0x1p`. The updated debt entry says "other incomplete exponent forms are not separately verified", but their behaviour changes too. FreeBSD 11.4's `parsefloat` also commits to the last valid prefix, so it gives 1 for all of these. Literals, main → PR: - `""`/`x`, `""`/` x`, `""`/`x%d`, `""`/`%%`: -1 → 0. - `x`/`x%d`: -1 on both. ` `/`x`: 0 on both. `a`/`b`: 0 on both. `5`/`%dx`: 1 on both. For a literal that meets end of input, FreeBSD 11.4's `vfwscanf` goes to `input_failure` and returns `EOF` when nothing was converted ([vfwscanf.c L490-L495, L783-L784](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdio/vfwscanf.c#L490-L495)). C11 7.29.2.2 also calls running out of input an input failure. So the new 0 rests only on the firmware result reported in #8479; neither FreeBSD nor the standard supports it. The `%%` case changes too, so it would help to say whether #8479 covered `%%`. AI-assisted: yes (Claude Code); results above were run on this machine.
xXPBSXx commented 2026-10-22 04:11:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:11:25Z.


Linux data point for c092916666 (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; GCC 13.3, Release, BUILD_TESTING=ON), this head merged onto main df2569d2c5 (clean merge). I built guest_wide_conversion_tests and guest_wide_stream_scan_tests and ran the executable directly (exit code, not through ctest):

  • With the PR: exit code 0 for both.
  • Without it (the PR's test sources on top of main, with core/libs/prx/libc/src/ScanningWide.cpp reset to main): guest_wide_conversion_tests exits 1 and guest_wide_stream_scan_tests aborts (SIGABRT, exit code 134).
    Not tested: macOS, Windows, the rest of the test suite.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332490347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9331#issuecomment-6332490347). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:11:25Z. --- Linux data point for `c092916666` (WSL2, Ubuntu 24.04, kernel 6.18 - a virtualised kernel, not bare-metal Linux; GCC 13.3, Release, `BUILD_TESTING=ON`), this head merged onto `main` `df2569d2c5` (clean merge). I built `guest_wide_conversion_tests` and `guest_wide_stream_scan_tests` and ran the executable directly (exit code, not through `ctest`): - With the PR: exit code 0 for both. - Without it (the PR's test sources on top of `main`, with `core/libs/prx/libc/src/ScanningWide.cpp` reset to `main`): `guest_wide_conversion_tests` exits 1 and `guest_wide_stream_scan_tests` aborts (SIGABRT, exit code 134). Not tested: macOS, Windows, the rest of the test suite. AI-assisted (Claude Code).
harisibrar1 commented 2026-10-22 13:42:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:42:50Z.

Review: COMMENTED


Checked against main 8b3e39832a and FreeBSD 11.4 lib/libc/stdio/vfwscanf.c (release/11.4.0), plus the "Remaining differences" in #8479:

  • The debt line seems to read main's "FreeBSD's vfwscanf reports an input failure for the first and converts the second" as being about 0x. On main, "the first" is the literal mismatch: vfwscanf.c L493-495 goes to input_failure when the character differs.
  • For 0x with %x, FreeBSD's parseint pushes back the x and converts the 0 (L405-418, with PFXOK from L565). So 0x/%x returns 1 with 0 there, not an input failure.
  • As written, the entry now says the wrong thing about 0x, and it no longer records that a/b%d returns 0 here but EOF on FreeBSD. Could the literal-mismatch divergence be kept, and the 0x clause say that FreeBSD converts it as 0?
  • Small one: the literal-at-end-of-input sentence could also say it follows #8479 and that FreeBSD returns EOF there, as the exponent sentence does.
  • #8306, #9087 and #6044 are all still open, and this PR merges and passes on main without them. If they are only shared-file overlaps, moving them out of "Depends on" might keep this from being held up.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615174230 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9331#pullrequestreview-5615174230). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T13:42:50Z. **Review:** COMMENTED --- Checked against main 8b3e39832a and FreeBSD 11.4 `lib/libc/stdio/vfwscanf.c` (release/11.4.0), plus the "Remaining differences" in #8479: - The debt line seems to read main's "FreeBSD's `vfwscanf` reports an input failure for the first and converts the second" as being about `0x`. On main, "the first" is the literal mismatch: [vfwscanf.c L493-495](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdio/vfwscanf.c#L493-L495) goes to `input_failure` when the character differs. - For `0x` with `%x`, FreeBSD's `parseint` pushes back the `x` and converts the `0` ([L405-418](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/lib/libc/stdio/vfwscanf.c#L405-L418), with `PFXOK` from L565). So `0x`/`%x` returns 1 with 0 there, not an input failure. - As written, the entry now says the wrong thing about `0x`, and it no longer records that `a`/`b%d` returns 0 here but `EOF` on FreeBSD. Could the literal-mismatch divergence be kept, and the `0x` clause say that FreeBSD converts it as 0? - Small one: the literal-at-end-of-input sentence could also say it follows #8479 and that FreeBSD returns `EOF` there, as the exponent sentence does. - #8306, #9087 and #6044 are all still open, and this PR merges and passes on main without them. If they are only shared-file overlaps, moving them out of "Depends on" might keep this from being held up. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9331
No description provided.