mirror of
https://github.com/lua/lua
synced 2024-11-22 04:41:23 +03:00
avoid undefined shift of LUA_NBITS in rotate operations
This commit is contained in:
parent
d2209c0741
commit
42cf5f8214
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbitlib.c,v 1.18 2013/03/19 13:19:12 roberto Exp $
|
||||
** $Id: lbitlib.c,v 1.18.1.1 2013/04/12 18:48:47 roberto Exp roberto $
|
||||
** Standard library for bitwise operations
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -129,7 +129,8 @@ static int b_rot (lua_State *L, int i) {
|
||||
b_uint 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