Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62fb934

Browse files
committed
Bug: Negation in 'luaV_shiftr' may overflow
Negation of an unchecked lua_Integer overflows with mininteger.
1 parent 8a32e0a commit 62fb934

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
766766
/*
767767
** Shift left operation. (Shift right just negates 'y'.)
768768
*/
769-
#define luaV_shiftr(x,y) luaV_shiftl(x,-(y))
769+
#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y))
770770

771771
lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
772772
if (y < 0) { /* shift right? */

testes/bitwise.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ assert(-1 >> numbits == 0 and
4545
-1 << numbits == 0 and
4646
-1 << -numbits == 0)
4747

48+
assert(1 >> math.mininteger == 0)
49+
assert(1 >> math.maxinteger == 0)
50+
assert(1 << math.mininteger == 0)
51+
assert(1 << math.maxinteger == 0)
52+
4853
assert((2^30 - 1) << 2^30 == 0)
4954
assert((2^30 - 1) >> 2^30 == 0)
5055

0 commit comments

Comments
 (0)