Skip to content

Parse full-range hex literals with strtoull#1233

Open
cuiweixie wants to merge 1 commit into
wren-lang:mainfrom
cuiweixie:fix/hex-literal-strtoull
Open

Parse full-range hex literals with strtoull#1233
cuiweixie wants to merge 1 commit into
wren-lang:mainfrom
cuiweixie:fix/hex-literal-strtoull

Conversation

@cuiweixie

Copy link
Copy Markdown

Summary

Hex integer literals are tokenized as 0x... and parsed with the C library. strtoll only covers the signed range; 0xFFFFFFFFFFFFFFFF (UINT64_MAX) overflows, sets ERANGE, and the lexer incorrectly reported "Number literal was too large".

Use strtoull so the full 64-bit unsigned range parses, then cast to double.

Regression

test/core/number/hex_literal_uint64_max.wren: fails with strtoll (compile error), passes with strtoull.

Testing

python3 util/test.py core/number/hex_literal_uint64_max
python3 util/test.py core/number

Hex literals like 0xFFFFFFFFFFFFFFFF exceed signed long long; strtoll
overflows and errno becomes ERANGE, incorrectly rejecting the literal.

Use strtoull and cast to double. Add a regression test for UINT64_MAX.
@cuiweixie cuiweixie force-pushed the fix/hex-literal-strtoull branch from 9f37a7c to 4a7f1fa Compare March 27, 2026 06:12
@CrazyInfin8

CrazyInfin8 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

As an alternative, in PR #984 I've attempted to create an entirely custom number parsing method. Which, should handle this case, but is certainly a much more aggressive change to the language and handles this a completely different way.

It'd consume as many digits that'd fit in the mantissa of a double (about what would fit in 52 bits), consume the rest ignoring the value but incrementing an exponent, then multiplies that mantissa value (as a long double) by the power of the base raised to the exponent.

Which should also prevent the overflow as we only parse enough to fit inside of about 52-bits of a 64-bit integer.

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.

2 participants