Skip to content

Commit 42cf5f8

Browse files
committed
avoid undefined shift of LUA_NBITS in rotate operations
1 parent d2209c0 commit 42cf5f8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lbitlib.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
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 $
33
** Standard library for bitwise operations
44
** See Copyright Notice in lua.h
55
*/
@@ -129,7 +129,8 @@ static int b_rot (lua_State *L, int i) {
129129
b_uint r = luaL_checkunsigned(L, 1);
130130
i &= (LUA_NBITS - 1); /* i = i % NBITS */
131131
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));
133134
lua_pushunsigned(L, trim(r));
134135
return 1;
135136
}

0 commit comments

Comments
 (0)