aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-07-09 15:31:01 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-07-09 15:31:01 -0300
commit2ef9bcfd118f263c06abfe2c04fe79a530ebe163 (patch)
treed8064683d0ced9910021f811796362445b61373b
parent5fa680d47f36d2f54d436d47beee2cb7dcf986cb (diff)
downloadlua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.tar.gz
lua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.tar.bz2
lua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.zip
avoid undefined shift of LUA_NBITS in rotate operation
-rw-r--r--lbitlib.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lbitlib.c b/lbitlib.c
index a76307b6..76d5358e 100644
--- a/lbitlib.c
+++ b/lbitlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbitlib.c,v 1.20 2013/06/21 17:27:24 roberto Exp roberto $ 2** $Id: lbitlib.c,v 1.21 2013/07/09 17:49:50 roberto Exp roberto $
3** Standard library for bitwise operations 3** Standard library for bitwise operations
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -128,7 +128,8 @@ static int b_rot (lua_State *L, int i) {
128 lua_Unsigned r = luaL_checkunsigned(L, 1); 128 lua_Unsigned r = luaL_checkunsigned(L, 1);
129 i &= (LUA_NBITS - 1); /* i = i % NBITS */ 129 i &= (LUA_NBITS - 1); /* i = i % NBITS */
130 r = trim(r); 130 r = trim(r);
131 r = (r << i) | (r >> (LUA_NBITS - i)); 131 if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */
132 r = (r << i) | (r >> (LUA_NBITS - i));
132 lua_pushunsigned(L, trim(r)); 133 lua_pushunsigned(L, trim(r));
133 return 1; 134 return 1;
134} 135}