diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-09 15:01:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-07-09 15:01:41 -0300 |
commit | 42cf5f8214edf45400c7e4abd6faef27cf424801 (patch) | |
tree | 7cf85dd6f3b3ce8d1da2eac310aa795add1233d3 | |
parent | d2209c07419aac2cac63dd6d31f5e886a2fdf7fa (diff) | |
download | lua-42cf5f8214edf45400c7e4abd6faef27cf424801.tar.gz lua-42cf5f8214edf45400c7e4abd6faef27cf424801.tar.bz2 lua-42cf5f8214edf45400c7e4abd6faef27cf424801.zip |
avoid undefined shift of LUA_NBITS in rotate operations
-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.18 2013/03/19 13:19:12 roberto Exp $ | 2 | ** $Id: lbitlib.c,v 1.18.1.1 2013/04/12 18:48:47 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 | */ |
@@ -129,7 +129,8 @@ static int b_rot (lua_State *L, int i) { | |||
129 | b_uint r = luaL_checkunsigned(L, 1); | 129 | b_uint r = luaL_checkunsigned(L, 1); |
130 | i &= (LUA_NBITS - 1); /* i = i % NBITS */ | 130 | i &= (LUA_NBITS - 1); /* i = i % NBITS */ |
131 | r = trim(r); | 131 | r = trim(r); |
132 | r = (r << i) | (r >> (LUA_NBITS - i)); | 132 | if (i != 0) /* avoid undefined shift of LUA_NBITS when i == 0 */ |
133 | r = (r << i) | (r >> (LUA_NBITS - i)); | ||
133 | lua_pushunsigned(L, trim(r)); | 134 | lua_pushunsigned(L, trim(r)); |
134 | return 1; | 135 | return 1; |
135 | } | 136 | } |