mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 03:23:45 +01:00
lua: apply patch for "Compiler can optimize away overflow check in table.unpack"
<https://lua.org/bugs.html#5.2.3-1>
This commit is contained in:
parent
88ffe75b58
commit
7362ecb3b4
@ -340,13 +340,14 @@ static int luaB_assert (lua_State *L) {
|
|||||||
|
|
||||||
|
|
||||||
static int luaB_unpack (lua_State *L) {
|
static int luaB_unpack (lua_State *L) {
|
||||||
int i, e, n;
|
int i, e;
|
||||||
|
unsigned int n;
|
||||||
luaL_checktype(L, 1, LUA_TTABLE);
|
luaL_checktype(L, 1, LUA_TTABLE);
|
||||||
i = luaL_optint(L, 2, 1);
|
i = luaL_optint(L, 2, 1);
|
||||||
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
|
e = luaL_opt(L, luaL_checkint, 3, luaL_getn(L, 1));
|
||||||
if (i > e) return 0; /* empty range */
|
if (i > e) return 0; /* empty range */
|
||||||
n = e - i + 1; /* number of elements */
|
n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */
|
||||||
if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */
|
if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n))
|
||||||
return luaL_error(L, "too many results to unpack");
|
return luaL_error(L, "too many results to unpack");
|
||||||
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
|
lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */
|
||||||
while (i++ < e) /* push arg[i + 1...e] */
|
while (i++ < e) /* push arg[i + 1...e] */
|
||||||
|
Loading…
Reference in New Issue
Block a user