Skip to content

[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
repo-assist/fix-strtod-erange-2026-04-13-6ecdac872e2f8f93
Draft

[Repo Assist] fix: add L_ERANGE and set errno on strtod/strtof overflow/underflow#126
github-actions[bot] wants to merge 2 commits intomainfrom
repo-assist/fix-strtod-erange-2026-04-13-6ecdac872e2f8f93

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

l_strtod and l_strtof did not set errno on overflow or underflow, diverging from POSIX strtod behaviour. This PR adds L_ERANGE and fixes both functions.

Root Cause

The exponent accumulation loops had no overflow detection. An input like "1e400" would silently produce +Inf without setting errno, and "1e-400" would silently produce 0.0 without setting errno.

Changes

  • l_os.h: Add L_ERANGE (value 34, matching POSIX ERANGE) with #define ERANGE L_ERANGE alias
  • l_strtod: Cap exponent loop at 400 iterations, detect +Inf result (overflow) and 0.0 from non-zero mantissa (underflow), call l_set_errno(L_ERANGE)
  • l_strtof: Same fix with cap at 100 iterations
  • tests/test_strings.c: Add overflow/underflow errno tests; save errno before TEST_ASSERT to avoid l_write clobbering l_last_errno
  • tests/coverage_manifest.json: Register tests/test_img.c

Test Status

✅ Linux gcc+clang: all assertions passed
⚠️ ARM/AArch64/RISC-V/Windows/WASI: not tested locally — CI will cover these

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

- 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>
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.
@github-actions
Copy link
Copy Markdown
Contributor Author

Commit pushed: f91977d

Generated by 🌈 Repo Assist at {run-started}. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants