Fix Lua type of zero

This change fixes a regression from 281a0f27 which resulted in the
integer literal `0` being interpreted as a floating point number. This
should also fix a reported issue with Fennel integration.
This commit is contained in:
Justine Tunney 2022-07-08 10:08:40 -07:00
parent fe5c475f83
commit 50a6df89b8
2 changed files with 11 additions and 1 deletions

View file

@ -32,6 +32,16 @@ assert(Bsf(0x80000001) == 0)
assert(Lemur64() == 0x1940efe9d47ae889)
assert(Lemur64() == 0xd4b3103f567f9974)
assert(EncodeLua(nil) == "nil")
assert(EncodeLua(0) == "0")
assert(EncodeLua(3.14) == "3.14")
assert(EncodeLua({1, 2}) == "{1, 2}")
assert(EncodeJson(nil) == "null")
assert(EncodeJson(0) == "0")
assert(EncodeJson(3.14) == "3.14")
assert(EncodeJson({1, 2}) == "[1,2]")
assert(hex(0x1940efe9d47ae889) == "0x1940efe9d47ae889")
assert(oct(0x1940efe9d47ae889) == "0145007376472436564211")
assert(bin(0x1940efe9d47ae889) == "0b0001100101000000111011111110100111010100011110101110100010001001")

View file

@ -293,7 +293,7 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
}
}
else if (s[0] == '0') { /* [jart] octal is the best radix */
for (s += 1; lisdigit(cast_uchar(*s)); s++) {
for (; lisdigit(cast_uchar(*s)); s++) {
int d = *s - '0';
if (a >= MAXBY8 && (a > MAXBY8 || d > MAXLASTD8 + neg)) /* overflow? */
return NULL; /* do not accept it (as integer) */