fix(libc): end a wide scanf at a positional $ as FreeBSD #11726
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11726"
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 cocoa55 on 2026-10-27T05:57:18Z.
Title: fix(libc): end a wide scanf at a positional $ as FreeBSD does
What
A scanf-family format that has a 16-bit wide conversion (
%ls,%lc,%l[,%S,%C) and ann$position used to throwNotImplemented("sscanf positional arguments with a 16-bit wide conversion").FreeBSD's
vfscanf, which the console's libc is based on, has non$support. It readsnas a field width, and the$is then an unknown conversion character, so the scan stops there as a matching failure and returns what it assigned so far. The in-process scanner (ScanSource) already does exactly that for any unknown conversion character, and main already relies on it for narrow%cformats (sscanf("a", "%2$2c%1$n", ...) == 0). So this PR only removes the guard:RequireNoPositionalWideScanis removed, so wide formats with a$now take the same path as the narrow%cformats.ScansWideInProcessis removed. Its callers now testHasGuestWideScandirectly.The debt entry now says that an
n$with a wide field fails at the$as in FreeBSD, and that this is unchecked on a console.This replaces the earlier version of this PR, which added glibc-style
n$support. Main has since pinned the FreeBSD behaviour in a test, so that version no longer fits.Tested
Run by Claude (AI) on Linux (Ubuntu, GCC 13.3), Release build with
-DBUILD_TESTING=ON, on top of current main:guest_formatting_tests:sscanf("a b", "%2$ls")returns 0 and leaves the buffer untouched, andsscanf("5 ab", "%d %1$ls")returns 1 with only the number assigned. These replace the old "%2$lsthrows" case.guest_wide_stream_scan_tests:fscanfwith%d %2$lsreturns 1, and the nextfgetcstill reads theaafter the$.srcchanges reverted,guest_formatting_testsaborts with the old "not implemented" error.guest_scan_count,guest_wide_formatting,guest_stdio_variadicpass.tools/check_conventions.pypasses, andtools/progress.pyshows no change in libc stubs.ScanSource, so the change applies there too.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T06:17:21Z.
Review: COMMENTED
One point in the argument-position description needs tightening. The code and PR text define what happens when a format mixes numbered assignments (
%n$) with unnumbered assignments, and say that this matches glibc. POSIX says those forms cannot be mixed in one format (except%%and assignment-suppressed%*conversions); otherwise the result is undefined: https://pubs.opengroup.org/onlinepubs/000095399/functions/fscanf.html. The added tests use numbered assignments throughout (the unnumbered%*lscase is suppressed), so they do not establish the mixed behavior claimed in the description. Please describe mixed assignment formats as unverified/unsupported, or add a test and document the chosen extension without attributing it to glibc. This is not a correctness blocker for formats that use numbered arguments consistently.