diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-09 15:31:01 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-09 15:31:01 -0300 |
commit | 2ef9bcfd118f263c06abfe2c04fe79a530ebe163 (patch) | |
tree | d8064683d0ced9910021f811796362445b61373b | |
parent | 5fa680d47f36d2f54d436d47beee2cb7dcf986cb (diff) | |
download | lua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.tar.gz lua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.tar.bz2 lua-2ef9bcfd118f263c06abfe2c04fe79a530ebe163.zip |
avoid undefined shift of LUA_NBITS in rotate operation
-rw-r--r-- | lbitlib.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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 | } |