diff options
author | Lua Team <team@lua.org> | 2015-02-26 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2015-02-26 12:00:00 +0000 |
commit | 4fd8751bd02b0618b975504491e2221ced98c8d4 (patch) | |
tree | ce972c3b21c96d9e7dfa59a4745e4fa0e6a18168 /src/ltablib.c | |
parent | 357e7cdc32cd4224b03748e4f284857e47f70a68 (diff) | |
download | lua-github-5.2.x.tar.gz |
Diffstat (limited to 'src/ltablib.c')
-rw-r--r-- | src/ltablib.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ltablib.c b/src/ltablib.c index 6001224e..99764d26 100644 --- a/src/ltablib.c +++ b/src/ltablib.c @@ -1,10 +1,11 @@ /* -** $Id: ltablib.c,v 1.65.1.1 2013/04/12 18:48:47 roberto Exp $ +** $Id: ltablib.c,v 1.65.1.2 2014/05/07 16:32:55 roberto Exp $ ** Library for Table Manipulation ** See Copyright Notice in lua.h */ +#include <limits.h> #include <stddef.h> #define ltablib_c @@ -134,13 +135,14 @@ static int pack (lua_State *L) { static int unpack (lua_State *L) { - int i, e, n; + int i, e; + unsigned int n; luaL_checktype(L, 1, LUA_TTABLE); i = luaL_optint(L, 2, 1); e = luaL_opt(L, luaL_checkint, 3, luaL_len(L, 1)); if (i > e) return 0; /* empty range */ - n = e - i + 1; /* number of elements */ - if (n <= 0 || !lua_checkstack(L, n)) /* n <= 0 means arith. overflow */ + n = (unsigned int)e - (unsigned int)i; /* number of elements minus 1 */ + if (n > (INT_MAX - 10) || !lua_checkstack(L, ++n)) return luaL_error(L, "too many results to unpack"); lua_rawgeti(L, 1, i); /* push arg[i] (avoiding overflow problems) */ while (i++ < e) /* push arg[i + 1...e] */ |