fix(libc): match reported wide scanf edge cases #9331
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9331"
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 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 ofEOF. Adds regressions for sized and unsized buffer scans and the stream scanner.The reported short
%cfield 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; builtguest_wide_conversion_testsandguest_wide_stream_scan_tests; CTest passedguest_wide_conversionandguest_wide_stream_scan(2/2). No PS5 runtime or hardware test was performed.python3 tools/check_conventions.py --base upstream/mainreports zero errors and one debt-length warning on the existing libc scanner entry. The required localorigin/mainreference is 10,325 commits behind upstream; checking against it reports unrelated historical findings outside this change.tools/pr_overlap.pyreports dependencies listed below.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 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
c092916666merged onto maina6dcea927(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.ScanningWide.cppfrom main,guest_wide_conversionfails andguest_wide_stream_scanaborts (0xc0000409).check_conventions.py: one warning,debt-lengthondocs/dev/debt/libc.md:128.swscanfwith%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, including1e,1exand hex0x1p. The updated debt entry says "other incomplete exponent forms are not separately verified", but their behaviour changes too. FreeBSD 11.4'sparsefloatalso 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
vfwscanfgoes toinput_failureand returnsEOFwhen 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.
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 ontomaindf2569d2c5(clean merge). I builtguest_wide_conversion_testsandguest_wide_stream_scan_testsand ran the executable directly (exit code, not throughctest):main, withcore/libs/prx/libc/src/ScanningWide.cppreset tomain):guest_wide_conversion_testsexits 1 andguest_wide_stream_scan_testsaborts (SIGABRT, exit code 134).Not tested: macOS, Windows, the rest of the test suite.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:42:50Z.
Review: COMMENTED
Checked against main
8b3e39832aand FreeBSD 11.4lib/libc/stdio/vfwscanf.c(release/11.4.0), plus the "Remaining differences" in #8479:vfwscanfreports an input failure for the first and converts the second" as being about0x. On main, "the first" is the literal mismatch: vfwscanf.c L493-495 goes toinput_failurewhen the character differs.0xwith%x, FreeBSD'sparseintpushes back thexand converts the0(L405-418, withPFXOKfrom L565). So0x/%xreturns 1 with 0 there, not an input failure.0x, and it no longer records thata/b%dreturns 0 here butEOFon FreeBSD. Could the literal-mismatch divergence be kept, and the0xclause say that FreeBSD converts it as 0?EOFthere, as the exponent sentence does.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.