diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-04 13:31:42 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-07-04 13:31:42 -0300 |
| commit | 8217e0d4fe4cf80c52328230614ab41cf32f4afe (patch) | |
| tree | 34682185e379af7210098dfa3d8c081042db4d97 | |
| parent | 319ccfefbc651fa22f264bdfa872ffe59cc81151 (diff) | |
| download | lua-8217e0d4fe4cf80c52328230614ab41cf32f4afe.tar.gz lua-8217e0d4fe4cf80c52328230614ab41cf32f4afe.tar.bz2 lua-8217e0d4fe4cf80c52328230614ab41cf32f4afe.zip | |
avoid subtle possibility of arithmetic overflow
| -rw-r--r-- | ltablib.c | 10 |
1 files changed, 5 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ltablib.c,v 1.79 2014/11/02 19:19:04 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.80 2015/01/13 16:27:29 roberto Exp roberto $ |
| 3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -215,10 +215,10 @@ static int unpack (lua_State *L) { | |||
| 215 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ | 215 | n = (lua_Unsigned)e - i; /* number of elements minus 1 (avoid overflows) */ |
| 216 | if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, (int)(++n))) | 216 | if (n >= (unsigned int)INT_MAX || !lua_checkstack(L, (int)(++n))) |
| 217 | return luaL_error(L, "too many results to unpack"); | 217 | return luaL_error(L, "too many results to unpack"); |
| 218 | do { /* must have at least one element */ | 218 | for (; i < e; i++) { /* push arg[i..e - 1] (to avoid overflows) */ |
| 219 | (*ta.geti)(L, 1, i); /* push arg[i..e] */ | 219 | (*ta.geti)(L, 1, i); |
| 220 | } while (i++ < e); | 220 | } |
| 221 | 221 | (*ta.geti)(L, 1, e); /* push last element */ | |
| 222 | return (int)n; | 222 | return (int)n; |
| 223 | } | 223 | } |
| 224 | 224 | ||
