fix(libc): keep errno when strtol converts nothing on macOS #6853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6853"
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 DavidSamir on 2026-10-16T14:17:32Z.
What
On macOS, a guest integer conversion of a subject with no digits sets
errnotoEINVAL:"","words"," +","\n";atoi,strtoland the rest of the family.macOS's
strtollandstrtoullsetEINVALthere, and the guest functions pass the host'serrnothrough.guest_atoi,guest_wide_conversionandguest_mathexpecterrnounchanged in these cases, as glibc leaves it, so all three fail on macOS onmain:A
ParseIntegerhelper inSonyCrt.hppcalls the host conversion. On macOS it restores the caller'serrnowhen nothing was converted and the base is 0 or 2 to 36:ERANGE;EINVAL;endptrand the value are unchanged;Every host
strtoll,strtoull,strtoimaxandstrtoumaxcall behind a guest export now goes through it:strtol,strtoul,strtoll,strtoull;atoi,atol,atoll;_Stoul,_Stoull;strtoimax,strtoumax;wcsto*integer conversions, and through them_WStoul.Commits:
Strings.cpp.RuntimeSupport.cpp.Tested
macOS 26.7.1, Apple M2, AppleClang 21.0.0, x86-64 under Rosetta, Release.
maindoesn't build the system libraries on macOS by itself, so the tests ran in a local tree:maince991f1ecwith the macOS runtime work merged (#4627, #4630, #6124, the macOS relinker PRs, mugurc's port branches). The branch's three files are identical to the ones tested.guest_atoiandguest_wide_conversionfail onmain's files and pass with this branch, 5 runs of 5.guest_mathgets past everystrtolandstrtoimaxcase. It then stops on an unrelated check:acosf(0.5f)returns0x3f860a91on macOS, one ulp from the0x3f860a92the test expects. A standalone program on this Mac gets the same bits from the host'sacosf.errnoafter every conversion, which also dropsERANGEon overflow, fails all three tests:atoi(9223372036854775808): expected -1, errno 34; received -1, errno 1234_WStoul overflow: … errno 0Guest strtol failed for '9223372036854775808!'guest_tests here, withmain's files and with this branch:guest_atoiandguest_wide_conversionare the only differences. The other 20 failures are the same with both.""and"\n"withstrtolin base 10 43 times in its first 45 s, each time withEINVALset onmain. A temporary log line in the helper counted them. Over 40 s its own log, with numbers masked, and the list of files it writes under/dataare the same withmain's files and with this branch, so it shows no visible difference in that time. The other 15 catalog titles run here for 45 s didn't reach the case.tools/check_conventions.py --base origin/mainandgit diff --checkpass.Not tested: Linux and Windows, where the helper calls the conversion unchanged.
Overlap: #6707 and #6133 edit
SonyCrt.hpp; #6541, #6447 and #6133 editRuntimeSupport.cpp; #6532 and #6144 editStrings.cpp. None of them changes these conversions. Whichever lands second rebases.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 github-actions[bot] on 2026-10-16T14:40:08Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/include/SonyCrt.hppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/Strings.cppcore/libs/prx/libc/src/RuntimeSupport.cppcore/libs/prx/libc/src/Strings.cppImported from boykopovar/AnyPS5. Originally posted by karimibrahim07 on 2026-10-17T03:52:26Z.
Review: COMMENTED
Windows check, since the description lists Windows as not tested. Head
8469126a6merged ontomaine3a8e4430(clean merge). Windows 11 Pro (26300), WinLibs GCC 15.2.0 r7 (UCRT), Ninja Release.guest_atoi,guest_wide_conversion,guest_math,guest_stringsandguest_qsortpass,--repeat until-fail:3. On WindowsParseIntegertakes the#elsebranch, so this confirms the change leaves Windows behaviour alone. These tests already expecterrnounchanged for a subject with no digits, and they pass, so the UCRT doesn't setEINVALthere either.Code: the macOS branch only restores
errnowhen nothing was converted, the host reportedEINVALand the base is valid. So an invalid base still reportsEINVAL, andERANGEcan't be hidden (it never comes withparsedEnd == text). Passing&parsedEndand copying it toendafterwards also covers theatoi/atolcallers, which pass a nullend. I have no code requests.Overlap with #6707 (mine): the bot reports a textual conflict at
SonyCrt.hppL23-25. #6707 removes thenamespace {thatParseIntegeris inserted after: it moves the constraint-handler slot out of the unnamed namespace so that every libc source file shares one handler (a review request there). If #6707 lands first, the resolution is to keepParseIntegerwhere it is, inside anamespace { }of its own or as a plaininlinefunction. Nothing else in the two PRs touches the same code. I'll do the rebase on my side if yours lands first.Not checked: macOS (no Mac here).
AI-assisted: yes. I ran the build and the tests above.
Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-17T06:24:11Z.
Independent native arm64 macOS conversion check and Linux control on exact head
8469126a6da4a4b46ffa1ff2aeb4c27cda5a0470.Scope first: this is an integer-export slice test, not a full libc/guest CTest run. I extracted the original integer conversion functions unchanged from
Strings.cppandRuntimeSupport.cpp, including the original prefix helpers, and compiled them against each revision's unchangedSonyCrt.hpp. Function-source hashes were recorded. Full native files cannot compile here because the unrelated long-double code requires x87 layout andFileStream.hpphits macOS stdio macro errors. No production implementation was patched for this test.Hosts: macOS 27.2 arm64, AppleClang 21.0.0 (executed natively); Ubuntu 24.04 x86-64, GCC 13.3/glibc.
The matrix calls all sixteen covered exports: eight narrow
strto*/_Stoul/_Stoullforms, fourwcsto*forms plus_WStoul, andatoi/atol/atoll. It checks exact values, errno and consumed positions with both null and non-null end pointers; 36 valid bases (0 and 2–36), five saved errno values, no-digit subjects, normal/prefixed conversions, signed/unsigned boundaries and overflow. Narrow exports also get invalid bases -1, 1 and 37.The Mac parent first fails with
strtol/strtoll/strtoimaxon no-digit input: errno 22 instead of the saved 0. A deliberately wrong helper that always restores errno fails 238 checks, including overflow returning the saturated value but clearingERANGE. Thus this is sensitive to the overbroad-restoration error, as well as checking the no-digit correction and end-pointer handling.No Rosetta/x86-64 guest ABI, complete wide-character suite, title, or current-main merge run is claimed. The Linux rows exercise the actual unchanged-host branch, rather than defining
__APPLE__on Linux.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T12:20:24Z.
Checked the diff: every host
strtoll/strtoull/strtoimax/strtoumaxcall behind a guest export goes throughParseInteger. On macOS it only restoreserrnowhen nothing was converted and the base is valid, soERANGEand the invalid-baseEINVALare kept; other hosts call the conversion unchanged. Windows confirmed by @karimibrahim07, macOS arm64 by @simonbbby.Rebased onto
main(the helper now sits inside the anonymous namespace thatmainmoved inSonyCrt.hpp); built and ran ctest on the rebase; merged.