mirror of
https://github.com/lua/lua
synced 2025-04-15 17:32:49 +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
|
** Standard library for bitwise operations
|
||||||
** See Copyright Notice in lua.h
|
** 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);
|
lua_Unsigned r = luaL_checkunsigned(L, 1);
|
||||||
i &= (LUA_NBITS - 1); /* i = i % NBITS */
|
i &= (LUA_NBITS - 1); /* i = i % NBITS */
|
||||||
r = trim(r);
|
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));
|
lua_pushunsigned(L, trim(r));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user