Use strtoll() for hex literals to handle 64-bit ones even on 32-bit.

This commit is contained in:
Bob Nystrom
2017-01-12 21:53:21 -08:00
parent 0cc00c41c0
commit 5ddd783ff5
3 changed files with 16 additions and 9 deletions
+12 -5
View File
@@ -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);
}