diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-07-22 13:44:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-07-22 13:44:53 -0300 |
commit | 62fb93442753cbfb828335cd172e71471dffd536 (patch) | |
tree | a989f061765866aefb7b1ba4724163241edee922 | |
parent | 8a32e0aa4afdfd575c329ce62baaf7a14888ed3b (diff) | |
download | lua-github-62fb93442753cbfb828335cd172e71471dffd536.tar.gz |
Bug: Negation in 'luaV_shiftr' may overflow
Negation of an unchecked lua_Integer overflows with mininteger.
-rw-r--r-- | lvm.c | 2 | ||||
-rw-r--r-- | testes/bitwise.lua | 5 |
2 files changed, 6 insertions, 1 deletions
@@ -766,7 +766,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) { /* ** Shift left operation. (Shift right just negates 'y'.) */ -#define luaV_shiftr(x,y) luaV_shiftl(x,-(y)) +#define luaV_shiftr(x,y) luaV_shiftl(x,intop(-, 0, y)) lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) { if (y < 0) { /* shift right? */ diff --git a/testes/bitwise.lua b/testes/bitwise.lua index 59781f5d..9509f7f0 100644 --- a/testes/bitwise.lua +++ b/testes/bitwise.lua @@ -45,6 +45,11 @@ assert(-1 >> numbits == 0 and -1 << numbits == 0 and -1 << -numbits == 0) +assert(1 >> math.mininteger == 0) +assert(1 >> math.maxinteger == 0) +assert(1 << math.mininteger == 0) +assert(1 << math.maxinteger == 0) + assert((2^30 - 1) << 2^30 == 0) assert((2^30 - 1) >> 2^30 == 0) |