[Repo Assist] fix: add L_ERANGE and set errno on strtod/strtof overflow/underflow#126
Draft
github-actions[bot] wants to merge 2 commits intomainfrom
Draft
Conversation
- Add L_ERANGE (34) error code with #define alias for ERANGE - l_strtod: cap exp loop at 400 iterations, detect IEEE 754 overflow (+inf) and underflow (0.0 from non-zero) and call l_set_errno(L_ERANGE) to match POSIX strtod behaviour - l_strtof: same fix; cap at 100 iterations - Add ERANGE overflow/underflow tests to test_strings.c - Save errno before TEST_ASSERT to avoid l_write clobbering l_last_errno Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
38 tasks
README.md is auto-generated by gen-docs.ps1; docs were restructured in #152. Drop the auto-generated coverage-table edit to unblock merging this PR.
Contributor
Author
|
Commit pushed:
|
26 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
l_strtodandl_strtofdid not seterrnoon overflow or underflow, diverging from POSIXstrtodbehaviour. This PR addsL_ERANGEand fixes both functions.Root Cause
The exponent accumulation loops had no overflow detection. An input like
"1e400"would silently produce+Infwithout setting errno, and"1e-400"would silently produce0.0without setting errno.Changes
l_os.h: AddL_ERANGE(value 34, matching POSIXERANGE) with#define ERANGE L_ERANGEaliasl_strtod: Cap exponent loop at 400 iterations, detect+Infresult (overflow) and0.0from non-zero mantissa (underflow), calll_set_errno(L_ERANGE)l_strtof: Same fix with cap at 100 iterationstests/test_strings.c: Add overflow/underflow errno tests; save errno beforeTEST_ASSERTto avoidl_writeclobberingl_last_errnotests/coverage_manifest.json: Registertests/test_img.cTest Status
✅ Linux gcc+clang: all assertions passed
⚠️ ARM/AArch64/RISC-V/Windows/WASI: not tested locally — CI will cover these