diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-09-22 13:10:39 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-09-22 13:10:39 -0300 |
| commit | deac067ed39a44c001599c0d15de09872496b2aa (patch) | |
| tree | d7373651e7d54a8ca5ffa4841379a4d9149164aa /ltablib.c | |
| parent | 2ff34717227b8046b0fdcb96206f11f5e888664e (diff) | |
| download | lua-deac067ed39a44c001599c0d15de09872496b2aa.tar.gz lua-deac067ed39a44c001599c0d15de09872496b2aa.tar.bz2 lua-deac067ed39a44c001599c0d15de09872496b2aa.zip | |
Avoid overflows when incrementing parameters in C
Any C function can receive maxinteger as an integer argument, and
therefore cannot increment it without some care (e.g., doing unsigned
arithmetic as the core does).
Diffstat (limited to 'ltablib.c')
| -rw-r--r-- | ltablib.c | 3 |
1 files changed, 2 insertions, 1 deletions
| @@ -59,8 +59,9 @@ static void checktab (lua_State *L, int arg, int what) { | |||
| 59 | 59 | ||
| 60 | 60 | ||
| 61 | static int tinsert (lua_State *L) { | 61 | static int tinsert (lua_State *L) { |
| 62 | lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */ | ||
| 63 | lua_Integer pos; /* where to insert new element */ | 62 | lua_Integer pos; /* where to insert new element */ |
| 63 | lua_Integer e = aux_getn(L, 1, TAB_RW); | ||
| 64 | e = luaL_intop(+, e, 1); /* first empty element */ | ||
| 64 | switch (lua_gettop(L)) { | 65 | switch (lua_gettop(L)) { |
| 65 | case 2: { /* called with only 2 arguments */ | 66 | case 2: { /* called with only 2 arguments */ |
| 66 | pos = e; /* insert new element at the end */ | 67 | pos = e; /* insert new element at the end */ |
