Fix OS-specific behavior caused by integer overflow on Lua numbers

This commit is contained in:
Gustaf Alhäll 2025-08-23 17:30:18 +02:00 committed by NepDisk
parent 41c584638e
commit 9986f9aaef

View file

@ -89,8 +89,12 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
int luaO_str2d (const char *s, lua_Number *result) {
char *endptr;
double r = lua_str2number(s, &endptr);
*result = (lua_Number)r;
long r = lua_str2number(s, &endptr);
if (r > INT32_MAX)
r = INT32_MAX;
else if (r < INT32_MIN)
r = INT32_MIN;
*result = (lua_Number)r;
if (endptr == s) return 0; /* conversion failed */
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
*result = cast_num(strtoul(s, &endptr, 16));