mirror of
https://github.com/lua/lua
synced 2024-11-25 22:29:39 +03:00
avoid undefined shift of LUA_NBITS in rotate operation
This commit is contained in:
parent
5fa680d47f
commit
2ef9bcfd11
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user