summaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-05-15 12:22:45 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-05-15 12:22:45 -0300
commitfd1672ba989d14273e9ba429518913d4a926ef6d (patch)
tree9b3011be9ebbf24bdae9d5425831298d5c7916f6 /lapi.c
parent1ddb251d86713b03b39250a27b268fcc8c8e3c6d (diff)
downloadlua-fd1672ba989d14273e9ba429518913d4a926ef6d.tar.gz
lua-fd1672ba989d14273e9ba429518913d4a926ef6d.tar.bz2
lua-fd1672ba989d14273e9ba429518913d4a926ef6d.zip
avoid non-conformant pointer arithmetic in api check for 'lua_rotate'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lapi.c b/lapi.c
index a1033587..7eca6b6a 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.211 2014/05/14 14:20:17 roberto Exp roberto $ 2** $Id: lapi.c,v 2.212 2014/05/14 18:32:30 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -204,9 +204,9 @@ LUA_API void lua_rotate (lua_State *L, int idx, int n) {
204 lua_lock(L); 204 lua_lock(L);
205 t = L->top - 1; /* end of stack segment being rotated */ 205 t = L->top - 1; /* end of stack segment being rotated */
206 p = index2addr(L, idx); /* start of segment */ 206 p = index2addr(L, idx); /* start of segment */
207 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
208 api_checkstackindex(L, idx, p); 207 api_checkstackindex(L, idx, p);
209 api_check(L, p <= m + 1 && m <= t, "invalid 'n'"); 208 api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
209 m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
210 reverse(L, p, m); /* reverse the prefix with length 'n' */ 210 reverse(L, p, m); /* reverse the prefix with length 'n' */
211 reverse(L, m + 1, t); /* reverse the suffix */ 211 reverse(L, m + 1, t); /* reverse the suffix */
212 reverse(L, p, t); /* reverse the entire segment */ 212 reverse(L, p, t); /* reverse the entire segment */