summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-07-09 15:01:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-07-09 15:01:41 -0300
commit42cf5f8214edf45400c7e4abd6faef27cf424801 (patch)
tree7cf85dd6f3b3ce8d1da2eac310aa795add1233d3
parentd2209c07419aac2cac63dd6d31f5e886a2fdf7fa (diff)
downloadlua-github-42cf5f8214edf45400c7e4abd6faef27cf424801.tar.gz
avoid undefined shift of LUA_NBITS in rotate operations
-rw-r--r--lbitlib.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lbitlib.c b/lbitlib.c
index 9637532e..cf5a577a 100644
--- a/lbitlib.c
+++ b/lbitlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbitlib.c,v 1.18 2013/03/19 13:19:12 roberto Exp $
+** $Id: lbitlib.c,v 1.18.1.1 2013/04/12 18:48:47 roberto Exp roberto $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
@@ -129,7 +129,8 @@ static int b_rot (lua_State *L, int i) {
b_uint r = luaL_checkunsigned(L, 1);
i &= (LUA_NBITS - 1); /* i = i % NBITS */
r = trim(r);
- r = (r << i) | (r >> (LUA_NBITS - i));
+ if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */
+ r = (r << i) | (r >> (LUA_NBITS - i));
lua_pushunsigned(L, trim(r));
return 1;
}