Skip to content

Return null from Num.fromString when strtod parses nothing#1232

Open
cuiweixie wants to merge 1 commit into
wren-lang:mainfrom
cuiweixie:fix/num-fromstring-strtod-no-parse
Open

Return null from Num.fromString when strtod parses nothing#1232
cuiweixie wants to merge 1 commit into
wren-lang:mainfrom
cuiweixie:fix/num-fromstring-strtod-no-parse

Conversation

@cuiweixie

@cuiweixie cuiweixie commented Mar 27, 2026

Copy link
Copy Markdown

Summary

After strtod, if no conversion was performed, end is unchanged (end == string->value per POSIX). Return null immediately instead of running the trailing-whitespace and length checks on that path.

Tests

python3 util/test.py core/number/from_string

@cuiweixie cuiweixie force-pushed the fix/num-fromstring-strtod-no-parse branch from 6d1b186 to 3c1c70e Compare March 27, 2026 06:03
If strtod performs no conversion, end equals the input pointer; return
null immediately. Without this, whitespace-only strings (e.g. three
spaces) incorrectly returned 0: the trailing-whitespace loop advanced
end to the terminator so the full-string check passed.

Add a regression test for whitespace-only input.
@cuiweixie cuiweixie force-pushed the fix/num-fromstring-strtod-no-parse branch from 3c1c70e to fa7ba63 Compare March 27, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant