Merge branch 'fixluanumbers' into 'master'

Fix OS-specific behavior caused by integer overflow on Lua numbers (SRB2Classic Port)

See merge request kart-krew-dev/ring-racers!9
This commit is contained in:
Eidolon 2025-09-15 20:56:01 -05:00
commit 9c7473a80b

View file

@ -7,6 +7,7 @@
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -89,8 +90,12 @@ int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
int luaO_str2d (const char *s, lua_Number *result) { int luaO_str2d (const char *s, lua_Number *result) {
char *endptr; char *endptr;
double r = lua_str2number(s, &endptr); long r = lua_str2number(s, &endptr);
*result = (lua_Number)r; 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 == s) return 0; /* conversion failed */
if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */
*result = cast_num(strtoul(s, &endptr, 16)); *result = cast_num(strtoul(s, &endptr, 16));