commit 2ef9bcfd118f263c06abfe2c04fe79a530ebe163
parent 5fa680d47f36d2f54d436d47beee2cb7dcf986cb
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 9 Jul 2013 15:30:36 -0300
avoid undefined shift of LUA_NBITS in rotate operation
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lbitlib.c b/lbitlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbitlib.c,v 1.20 2013/06/21 17:27:24 roberto Exp roberto $
+** $Id: lbitlib.c,v 1.21 2013/07/09 17:49:50 roberto Exp roberto $
** Standard library for bitwise operations
** See Copyright Notice in lua.h
*/
@@ -128,7 +128,8 @@ static int b_rot (lua_State *L, int i) {
lua_Unsigned 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;
}