fix: replace strtol with strtoll for 64-bit hex literal parsing on 32-bit platforms
The previous implementation used strtol() for parsing hex literals, which only supports up to 32-bit values on 32-bit architectures. This caused hex literals larger than 0x7FFFFFFF to overflow or fail. Changed to strtoll() which guarantees 64-bit parsing regardless of platform word size. Also updated the error message to include the actual sizeof(long int) for debugging, uncommented the previously disabled 64-bit hex literal examples in syntax.wren, and added a test case for 0xdeadbeef to verify the fix works correctly.
This commit is contained in:
+12
-5
@@ -712,16 +712,23 @@ static void makeNumber(Parser* parser, bool isHex)
|
||||
{
|
||||
errno = 0;
|
||||
|
||||
// We don't check that the entire token is consumed because we've already
|
||||
// scanned it ourselves and know it's valid.
|
||||
parser->current.value = NUM_VAL(isHex ? strtol(parser->tokenStart, NULL, 16)
|
||||
: strtod(parser->tokenStart, NULL));
|
||||
if (isHex)
|
||||
{
|
||||
parser->current.value = NUM_VAL(strtoll(parser->tokenStart, NULL, 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
parser->current.value = NUM_VAL(strtod(parser->tokenStart, NULL));
|
||||
}
|
||||
|
||||
if (errno == ERANGE)
|
||||
{
|
||||
lexError(parser, "Number literal was too large.");
|
||||
lexError(parser, "Number literal was too large (%d).", sizeof(long int));
|
||||
parser->current.value = NUM_VAL(0);
|
||||
}
|
||||
|
||||
// We don't check that the entire token is consumed after calling strtoll()
|
||||
// or strtod() because we've already scanned it ourselves and know it's valid.
|
||||
|
||||
makeToken(parser, TOKEN_NUMBER);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user