fix(libc): leave errno alone for out-of-range float and double in swscanf #9973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9973"
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 JJenkx on 2026-10-23T01:26:17Z.
What
The wide scanf family (
swscanfand the stream forms that run its scanner) converts%f,%e,%gand%awithstrtof,strtodorstrtold. Those setERANGEwhen the value overflows or underflows. Thelibc.prxthat titles ship stores the same infinity or zero, but setsERANGEonly for along double:errnomainerrno1e39,1e-50%f,%eERANGE1e400,1e-400%lfERANGE1e5000,1e-5000,1e4933%Lf,%LeERANGEERANGE1e-4950(a representablelong double)%LfThe narrow
sscanfof the same copies gives the sameerrnoin all these cases. This PR restoreserrnoafter thefloatanddoubleconversions. Thelong doubleone keepsstrtold'sERANGE. Values are unchanged.Remaining gaps. Narrow
sscanfdelegates floating conversions to host libc on both Linux and Windows. Out-of-range%f/%eand%lfcan therefore still leak hostERANGE; this PR fixes the wide scanner only. The unchangedstrtoldpath also differs between hosts: on Linux/glibc 2.44,1e-4950setsERANGE, including in the host narrow%Lfscan, whereas the Windows and bundled-library results in the table leave it unchanged. Fixing these gaps requires per-field errno handling while retaining legitimate range errors from other conversions in the same call.Tested
Current reviewer-requested Linux refresh (2026-10-25): exact head
c228d7a459cea0e7dca1f8972915786c14d23d64directly on main3a930342d5a2189b78643818f04b8948fc4c3dc9, two topic commits without merge commits. The entire production scanner is current main plus the originalFloatmethod and<cerrno>include; that method and the original eleven-line regression block are unchanged from previous head93d553448df31ae614cfd28f9eedc9378fac0648. Main's canonicalApi.hppinclude, newer%S/%Cmatching-failure behavior and all its other scanner/test changes are retained.The debt resolution preserves every current-main row and records the confirmed wide float/double errno contract plus both known remaining gaps in a separate concise
floating scan errnoentry. It keeps main's newer scanner descriptions rather than restoring the older combined paragraph.Fresh Linux x86-64 Release libc and all eight scanner test executables built. The eight scanner groups from the earlier Linux report plus
public_headerseach pass three runs (27 passes). Keeping candidate tests and substituting only exact main productionScanningWide.cppmakesguest_wide_conversionfail on the three added float/double overflow/underflow errno checks; the other eight groups pass 24/24. Restored candidate gives 27 passes and a byte-identical rawlibc.prx. Conventions, whitespace and merge-tree checks pass.Exact-head logs, main-source negative control and complete-file preservation proof (SHA-256
b3ddb52a9674c73bd32396624e26dca3923b9c92c118f95941b335c1556a76c7). This directly addresses the request to refresh main while retaining the errno cases and documented gaps. Earlier Windows and module differential results below stay pinned to their measured revisions and were not rerun; no new Windows, original-module, game/GPU, console or performance result is claimed.Earlier validation (historical source pins)
Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release,
BUILD_TESTING=ON,mainccab14d394, head 783b351490.libc.prxnatively and compares itsswscanfwith this build'sswscanf_nid_postfix. It checks the result, the value,%nanderrnoon 60,000 random inputs per format:%d %u %i %x %lld %hd %f %lf %e, with signs, prefixes, digits and large values.main,%fand%ediffer on 557 and 593 inputs, allerrno.guest_wide_conversion: new checks cover an overflowing%fand%lfand an underflowing%lfand%ewitherrnoleft at 0, and a%Lfof1e-5000withERANGE. The wide, scanning, stream, libc and string tests (33) pass in three runs out of three. Withmain'sScanningWide.cppand these checks,guest_wide_conversionfails.python tools/check_conventions.py --base origin/mainandgit diff --checkpass.ScanningWide.cpp, but not the float conversion. #9863 merges cleanly. #8306 conflicts only indocs/dev/debt/libc.md, which this PR does not touch, and it already conflicts withmainthere. #6879 already conflicts withmainin several files.sscanfof1e50with%f,1e500and1e-500with%lf, and1e-4950with%Lfeach assigns one field and setsERANGEin three repetitions. Normal1with%Lfpreserves errno sentinel 123. Hoststrtold("1e-4950")also setsERANGE. This probe does not execute AnyPS5 or establish console behavior.ccab14d39455dd88eb5eda9e926709fe8c799f7band candidate783b3514900de7a50342ee0353b81be28bf36d5feach pass all 8 selected CTests in one run:guest_scan_count,guest_wide_formatting,guest_wide_strings,guest_wide_conversion,guest_wide_stream_scan,guest_stdio_variadic,guest_formatting, andguest_strings. The negative control, base production source plus the candidate regression test (f6dbc52d895d21e7b7e62ac462918ed0621d7cf0), passes 7/8 and fails onlyguest_wide_conversionon the three new overflow/underflow errno checks. Linux test report. These are CPU regression results, with no native title or performance claim.Checklist
main; no other open PR changes the wide float conversion'serrnoNotImplemented_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)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-23T03:16:32Z.
Review: COMMENTED
Checked against main
3875f8c8ffand glibcstdlib/strtod_l.c(reading only):ScanningWide.cpppassesstrtof/strtod'sERANGEstraight through to the guest, since__error_nid_postfixreturns&errno. Restoring it only in theland default branches keepsstrtold'sERANGEfor%Lf, as your table says. It still merges cleanly with main.docs/dev/debt/libc.md, next to the existing "The scanf family" entries, for the gap you describe under "Not changed"? On main, narrowsscanfgoes to the host on both platforms (Formatting.cpp:97uses glibc's__isoc99_vsscanf,:99usesstd::vsscanf), so an out-of-range%f/%e/%lfthere still setsERANGE. Right now that is only recorded in the PR text.round_and_returnsuggestsstrtold("1e-4950")(a subnormallong double) setsERANGEthere. If so, the "unchanged" in the1e-4950row holds on Windows only, and both%Lfand narrowsscanfwould differ from the console on Linux. Worth mentioning in the same debt line if you can confirm it.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T04:16:34Z.
Review: CHANGES_REQUESTED
Reviewed exact head 783b3514900de7a50342ee0353b81be28bf36d5f. The conversion change is narrow and consistent with the submitted console differential: restoring the prior errno for
%f/%e/%g/%afloat and double conversions preserves the converted values while leavingstrtold's range result intact. The reported 60,000-input-per-format native comparisons and focused regression cases are strong evidence. Current-main conventions andgit diff --checkpass; all listed relinker, sanitizer, register-context and write-watch checks pass. Product builds are skipped by policy. I could not rerunguest_wide_conversionlocally because this workspace has no configured AnyPS5 build/test executable.I am requesting one documentation change before approval: the existing
The scanf family/swscanfdebt entry does not yet describe this errno contract or the remaining gaps listed in the PR (narrow scans still inherit hostERANGE, and glibc'sstrtolddiffers for representable subnormal long doubles). Please record the confirmed wide-scan behavior and these known differences indocs/dev/debt/libc.md; the PR description alone will not travel with the implementation.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T14:27:37Z.
Review: DISMISSED
I rechecked exact head
907cae23fd4494ee741768582eb20fc77f161110. The documentation follow-up addresses my earlier request, and the reported Windowsguest_wide_conversionrerun is on this head. Exact conventions and whitespace checks pass; the PR's focused runtime evidence is still the contributor-reported Windows three-run result and the earlier Linux negative-control run. Hosted product jobs are skipped.I can't approve the current head yet because it is 423 commits behind live
main(e94545a5, merge base0db47b263d).GuestWideConversion.cppanddocs/dev/debt/libc.mdboth changed on main after that base.check_main_sync.pyreports a clean merge, but CONTRIBUTING requires branches to stay current; please merge/rebase current main, preserve the new errno cases and debt wording, and rerunguest_wide_conversionplus conventions on that exact refreshed head. The implementation file itself has no intervening main changes.