From fd1672ba989d14273e9ba429518913d4a926ef6d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 15 May 2014 12:22:45 -0300 Subject: avoid non-conformant pointer arithmetic in api check for 'lua_rotate' --- lapi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lapi.c') diff --git a/lapi.c b/lapi.c index a1033587..7eca6b6a 100644 --- a/lapi.c +++ b/lapi.c @@ -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 */ -- cgit v1.2.3-55-g6feb