diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-15 12:22:45 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-05-15 12:22:45 -0300 |
| commit | fd1672ba989d14273e9ba429518913d4a926ef6d (patch) | |
| tree | 9b3011be9ebbf24bdae9d5425831298d5c7916f6 /lapi.c | |
| parent | 1ddb251d86713b03b39250a27b268fcc8c8e3c6d (diff) | |
| download | lua-github-fd1672ba989d14273e9ba429518913d4a926ef6d.tar.gz | |
avoid non-conformant pointer arithmetic in api check for 'lua_rotate'
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -1,5 +1,5 @@ /* -** $Id: lapi.c,v 2.211 2014/05/14 14:20:17 roberto Exp roberto $ +** $Id: lapi.c,v 2.212 2014/05/14 18:32:30 roberto Exp roberto $ ** Lua API ** See Copyright Notice in lua.h */ @@ -204,9 +204,9 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) { lua_lock(L); t = L->top - 1; /* end of stack segment being rotated */ p = index2addr(L, idx); /* start of segment */ - m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ api_checkstackindex(L, idx, p); - api_check(L, p <= m + 1 && m <= t, "invalid 'n'"); + api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); + m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ reverse(L, p, m); /* reverse the prefix with length 'n' */ reverse(L, m + 1, t); /* reverse the suffix */ reverse(L, p, t); /* reverse the entire segment */ |
