fix(libc): end swscanf at %S and %C as a matching failure #8306

Merged
ZSWolt merged 2 commits from upstream-pr/8306 into main 2026-10-24 06:54:57 +00:00
ZSWolt commented 2026-10-20 09:39:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ZSWolt on 2026-10-20T09:39:35Z.


What

swscanf, swscanf_s (and vswscanf, which shares the scanner) threw unsupported conversion for %S and %C. They now end the scan as a matching failure. The call returns the number of fields assigned before the directive, and nothing is stored for it or for any later directive. The same applies with a length modifier (%lS, %hC, …) or with *.

This follows what @oneandonlydean found in the console's libc.prx shipped by PPSA21564 (review below): its wide scanner is Dinkumware's, and it treats S and C like an unknown conversion letter. An earlier revision of this PR read them as %ls/%lc after FreeBSD's vfwscanf.c, which the console does not do. That reading is dropped.

The behavior was read from the module, not run on a console. Whether input that ends before %S/%C gives EOF instead of the count is unverified and recorded in docs/dev/debt/libc.md.

Tested

  • Windows 11 with WSL2, Ubuntu 26.04.1, GCC 15.2.0, Release, BUILD_TESTING=ON.

  • guest_wide_conversion checks, for both swscanf_s and swscanf:

    • %S, %lS, %3S, %C, %lC, %hC and %*S assign nothing and leave the destination untouched.
    • The return value counts only the earlier assignments ("%d%3S%d" → 1), and later conversions are not performed.

    With main's ScanningWide.cpp these checks abort with swscanf_s: unsupported conversion 83; with this change they pass.

  • Full ctest: 1719/1719 pass on current main with this change. Vulkan tests are skipped under WSL.

  • tools/check_conventions.py: 0 errors. Its one debt-length warning is on the swscanf entry in docs/dev/debt/libc.md, which is already 2,165 characters on main. This change only rewrites its %S/%C clause.

  • tools/pr_overlap.py found no overlapping exports. Of the PRs it could not compare: #6879 changes unrelated lines in ScanningWide.cpp, #6044 only renames GuestWideConversion.cpp, and none of the PRs listed for docs/dev/debt/libc.md mention swscanf. #8292 adds vswscanf/vswscanf_s through the same WideScanner, so they get this behavior too, and the diffs don't touch the same lines.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4933907177 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8306). Originally posted by [ZSWolt](https://github.com/ZSWolt) on 2026-10-20T09:39:35Z. --- ### What `swscanf`, `swscanf_s` (and `vswscanf`, which shares the scanner) threw `unsupported conversion` for `%S` and `%C`. They now end the scan as a matching failure. The call returns the number of fields assigned before the directive, and nothing is stored for it or for any later directive. The same applies with a length modifier (`%lS`, `%hC`, …) or with `*`. This follows what @oneandonlydean found in the console's `libc.prx` shipped by PPSA21564 (review below): its wide scanner is Dinkumware's, and it treats `S` and `C` like an unknown conversion letter. An earlier revision of this PR read them as `%ls`/`%lc` after FreeBSD's `vfwscanf.c`, which the console does not do. That reading is dropped. The behavior was read from the module, not run on a console. Whether input that ends before `%S`/`%C` gives `EOF` instead of the count is unverified and recorded in `docs/dev/debt/libc.md`. ### Tested - Windows 11 with WSL2, Ubuntu 26.04.1, GCC 15.2.0, Release, `BUILD_TESTING=ON`. - `guest_wide_conversion` checks, for both `swscanf_s` and `swscanf`: - `%S`, `%lS`, `%3S`, `%C`, `%lC`, `%hC` and `%*S` assign nothing and leave the destination untouched. - The return value counts only the earlier assignments (`"%d%3S%d"` → 1), and later conversions are not performed. With main's `ScanningWide.cpp` these checks abort with `swscanf_s: unsupported conversion 83`; with this change they pass. - Full `ctest`: 1719/1719 pass on current main with this change. Vulkan tests are skipped under WSL. - `tools/check_conventions.py`: 0 errors. Its one `debt-length` warning is on the `swscanf` entry in `docs/dev/debt/libc.md`, which is already 2,165 characters on main. This change only rewrites its `%S`/`%C` clause. - `tools/pr_overlap.py` found no overlapping exports. Of the PRs it could not compare: #6879 changes unrelated lines in `ScanningWide.cpp`, #6044 only renames `GuestWideConversion.cpp`, and none of the PRs listed for `docs/dev/debt/libc.md` mention `swscanf`. #8292 adds `vswscanf`/`vswscanf_s` through the same `WideScanner`, so they get this behavior too, and the diffs don't touch the same lines. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
oneandonlydean commented 2026-10-20 18:16:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T18:16:50Z.


Thanks. Before this goes in I checked the console's own libc.prx (read from the module that a retail title, PPSA21564, ships). Its wide scanner is Dinkumware's, not FreeBSD's, and it doesn't read %S or %C as %ls/%lc:

  • swscanf, vswscanf and swscanf_s share one scanner. It treats S and C the same as an unknown conversion letter: the directive is an invalid conversion, and scanning stops there. s, c, [, n, d, p and the others are handled normally. An l qualifier doesn't change this.
  • So on the console, swscanf(u"Āb cd", u"%S", buf) assigns nothing, rather than reading "Āb".

Main throws for %S/%C, which at least reports the gap loudly. Following FreeBSD here would make a title silently read data the console never would. Suggested shape: either keep the throw, or treat %S/%C (with or without a qualifier) as a matching failure that returns what was assigned before them, and test that.

This comes from reading the module, not from running on a console.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297933775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8306#issuecomment-6297933775). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T18:16:50Z. --- Thanks. Before this goes in I checked the console's own `libc.prx` (read from the module that a retail title, PPSA21564, ships). Its wide scanner is Dinkumware's, not FreeBSD's, and it doesn't read `%S` or `%C` as `%ls`/`%lc`: - `swscanf`, `vswscanf` and `swscanf_s` share one scanner. It treats `S` and `C` the same as an unknown conversion letter: the directive is an invalid conversion, and scanning stops there. `s`, `c`, `[`, `n`, `d`, `p` and the others are handled normally. An `l` qualifier doesn't change this. - So on the console, `swscanf(u"Āb cd", u"%S", buf)` assigns nothing, rather than reading `"Āb"`. Main throws for `%S`/`%C`, which at least reports the gap loudly. Following FreeBSD here would make a title silently read data the console never would. Suggested shape: either keep the throw, or treat `%S`/`%C` (with or without a qualifier) as a matching failure that returns what was assigned before them, and test that. This comes from reading the module, not from running on a console.
ZSWolt commented 2026-10-20 19:00:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ZSWolt on 2026-10-20T19:00:13Z.


Thanks. Before this goes in I checked the console's own libc.prx (read from the module that a retail title, PPSA21564, ships). Its wide scanner is Dinkumware's, not FreeBSD's, and it doesn't read %S or %C as %ls/%lc:

  • swscanf, vswscanf and swscanf_s share one scanner. It treats S and C the same as an unknown conversion letter: the directive is an invalid conversion, and scanning stops there. s, c, [, n, d, p and the others are handled normally. An l qualifier doesn't change this.
  • So on the console, swscanf(u"Āb cd", u"%S", buf) assigns nothing, rather than reading "Āb".

Main throws for %S/%C, which at least reports the gap loudly. Following FreeBSD here would make a title silently read data the console never would. Suggested shape: either keep the throw, or treat %S/%C (with or without a qualifier) as a matching failure that returns what was assigned before them, and test that.

This comes from reading the module, not from running on a console.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298813865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8306#issuecomment-6298813865). Originally posted by [ZSWolt](https://github.com/ZSWolt) on 2026-10-20T19:00:13Z. --- > Thanks. Before this goes in I checked the console's own `libc.prx` (read from the module that a retail title, PPSA21564, ships). Its wide scanner is Dinkumware's, not FreeBSD's, and it doesn't read `%S` or `%C` as `%ls`/`%lc`: > > * `swscanf`, `vswscanf` and `swscanf_s` share one scanner. It treats `S` and `C` the same as an unknown conversion letter: the directive is an invalid conversion, and scanning stops there. `s`, `c`, `[`, `n`, `d`, `p` and the others are handled normally. An `l` qualifier doesn't change this. > * So on the console, `swscanf(u"Āb cd", u"%S", buf)` assigns nothing, rather than reading `"Āb"`. > > Main throws for `%S`/`%C`, which at least reports the gap loudly. Following FreeBSD here would make a title silently read data the console never would. Suggested shape: either keep the throw, or treat `%S`/`%C` (with or without a qualifier) as a matching failure that returns what was assigned before them, and test that. > > This comes from reading the module, not from running on a console.
MarcZX10 commented 2026-10-21 18:36:40 +00:00 (Migrated from github.com)

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


Overlap coordination for a follow-up to #9321: I have a narrow patch for the reported incomplete-exponent and literal-at-EOF cases. Its scanner code hunks are separate from this PR's %S/%C change, but it currently edits the same libc debt bullet, which pr_overlap.py flags. Would you prefer that follow-up to depend on this PR and update the debt entry after yours merges, or do you have another sequencing preference?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323641344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8306#issuecomment-6323641344). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T18:36:40Z. --- Overlap coordination for a follow-up to #9321: I have a narrow patch for the reported incomplete-exponent and literal-at-EOF cases. Its scanner code hunks are separate from this PR's `%S`/`%C` change, but it currently edits the same libc debt bullet, which `pr_overlap.py` flags. Would you prefer that follow-up to depend on this PR and update the debt entry after yours merges, or do you have another sequencing preference?
ZSWolt commented 2026-10-21 18:54:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ZSWolt on 2026-10-21T18:54:52Z.


@MarcZX10 Thanks for checking. Making your follow-up depend on this PR and updating the debt entry once it merges works for me. In that bullet I only rewrite the %S/%C clause, so rebasing your scanner change on top should leave the rest for you.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324000036 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8306#issuecomment-6324000036). Originally posted by [ZSWolt](https://github.com/ZSWolt) on 2026-10-21T18:54:52Z. --- @MarcZX10 Thanks for checking. Making your follow-up depend on this PR and updating the debt entry once it merges works for me. In that bullet I only rewrite the `%S`/`%C` clause, so rebasing your scanner change on top should leave the rest for you.
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!8306
No description provided.