Fix crash in math.random if a max size interval is specified

This commit is contained in:
Tamás Bálint Misius 2023-07-20 21:33:43 +02:00
parent 53d573ad3c
commit 26a17c4e1f
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -200,7 +200,16 @@ static int mathRandom(lua_State *l)
{
luaL_error(l, "interval is empty");
}
if (upper - lower + 1)
{
lua_pushinteger(l, rng.between(lower, upper));
}
else
{
// The interval is *so* not empty that its size overflows 32-bit integers
// (only possible if it's exactly 0x100000000); don't use between.
lua_pushinteger(l, int(rng()));
}
return 1;
}