fix(libc): return +0 from strtod and friends when no conversion is performed #2725
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2725"
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 husseinkad on 2026-10-10T12:19:55Z.
What
On Windows the guest
strtod,strtof,strtold,wcstod,wcstofandwcstoldpassed straight through to the host, which returns-0.0when a sign prefix is not followed by a number:strtod("-.", &e),"-x","-.e1","- 1","-e5"all returned-0.0with nothing consumed (e == nptr). FreeBSD's gdtoastrtod.ctakes itsret0path there (s = s00; sign = 0;) and returns+0.0;strtodg.c(used forstrtold) clears the sign forSTRTOG_NoNumberthe same way, and the wide functions go through the narrow ones. C17 7.22.1.3 only says that zero is returned when no conversion could be performed.A small helper returns
+0when the host consumed nothing (it detects that itself, so a nullendptrworks), and leaves every real conversion alone, including those that give-0.0(-0,-.0,-0e5,-0x0p0,-0xconsuming-0).atofnow callsstrtod(str, NULL)as FreeBSD's does, so it gets the same fix; for the stringnanit returns the quiet NaN0x7ff8...instead of the CRT's0x7fff..., and it now setsERANGEon overflow likestrtod.A lead from the same audit,
strtod("nan(a b)")consuming all 8 characters, is not a defect: FreeBSD'shexnan.caccepts whitespace inside the parentheses too, so it is left alone.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_mathgains the no-conversion shapes (""," ","-","+","-.","+.","-x","-.e1","-e5","- 1"," -.") for double, float and long double, a nullendptr, the wide variants, the-0conversions that must keep their sign,-inf, andatof("nan"); it fails without the change (exit0xc0000409) and passes with it.ctest -R "guest_(math|wide_strings|wide_formatting|strings|formatting)$"passes.libc.prxside by side over 937 million inputs (all 917 million strings of length 0 to 6 over+-.0123456789eExXpPaAfFnNiI _()plus 20 million random numeric-looking strings with whitespace kinds, embedded NULs, non-ASCII characters,nan(...)forms), comparing value bits (x87 for long double), end offset anderrnofor the six functions and with a nullendptr: 0 unintended differences; the only changes are -0.0 becoming +0.0 where nothing was consumed (about 20 million cases) and theatofNaN bits andERANGE; no real conversion lost its sign.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T12:20:04Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed