mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
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:
commit
9c7473a80b
1 changed files with 7 additions and 2 deletions
|
|
@ -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));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue