Skip to content

feat(libc): scan 16-bit wide conversions in the sscanf family on Linux - #5606

Closed
Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:feat/libc-sscanf-wide-linux
Closed

Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:feat/libc-sscanf-wide-linux

Conversation

@Gashrod1

Copy link
Copy Markdown
Contributor

What

On Linux, sscanf, vsscanf, sscanf_s and vsscanf_s threw for the 16-bit wide conversions %ls, %lc, %l[, %S and %C (#3984), because glibc would store a 32-bit wchar_t per character into the guest's 16-bit buffer. Windows already handed them to its host, whose wchar_t is 16 bits.

When the format has such a conversion, these functions now go through the per-directive scanner the _s forms already use (ScanGuest). Each wide directive is scanned as its narrow form into a temporary buffer, then each byte is widened to one char16_t, as the C locale of FreeBSD 11's none.c converts a byte to the wide character of the same value. %ls and %l[ are terminated, %lc is not, and in the _s forms the capacity counts 16-bit characters (a string that does not fit stores an empty string, as for %s). Formats without a wide conversion still go to the host unchanged.

A wide conversion combined with a positional argument or the ' flag still throws, as ScanGuest handles neither. fscanf keeps throwing for wide conversions: it reads from a host stream and needs separate handling. On Windows, sscanf, vsscanf and fscanf still throw for %S and %C, which their format translation does not accept; that is unchanged here. The technical debt entry is updated accordingly.

guest_formatting replaces the Linux rejection checks with checks on both platforms for %ls, %lc with a width, %l[ through vsscanf, a byte above 0x7f, the _s capacity (fit, overflow, %lc), empty input and the remaining rejections, plus %S and %C on Linux. It aborts on main and passes with the change.

Tested

Linux (Arch, GCC), Release, BUILD_TESTING=ON, based on main ce5c83953: guest_formatting aborts on main and passes with the change (3 runs); full build and full ctest pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, BUILD_TESTING=ON: full build and full ctest pass (1111 tests, the same 8 skipped as on main; guest_formatting was rerun after restricting the %S/%C cases to Linux and passes, 3 runs). No title or homebrew run.

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

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#3987 core/libs/tests/Formatting.cpp L247-255
#4966 core/libs/prx/libc/src/Formatting.cpp L396
#5285 core/libs/prx/libc/src/Formatting.cpp L374, L393, L396
docs/dev/debt/libc.md L56
#5291 core/libs/prx/libc/src/Formatting.cpp L98-99, L374, L393, L396
docs/dev/debt/libc.md L56

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants