Commit a4d55881 authored by murase_syuka's avatar murase_syuka Committed by Yukihiro "Matz" Matsumoto

Bugfix lshift() bit overflow; close #3023

parent 22464fe5
......@@ -821,7 +821,8 @@ static mrb_value
lshift(mrb_state *mrb, mrb_int val, mrb_int width)
{
mrb_assert(width > 0);
if (width > NUMERIC_SHIFT_WIDTH_MAX) {
if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
(val > (MRB_INT_MAX >> width))) {
mrb_float f = (mrb_float)val;
while (width--) {
f *= 2;
......
......@@ -147,6 +147,9 @@ assert('Integer#<<', '15.2.8.3.12') do
# Left Shift by a negative is Right Shift
assert_equal 23, 46 << -1
# Left Shift by 31 is bitShift overflow to SignedInt
assert_equal 2147483648, 1 << 31
end
assert('Integer#>>', '15.2.8.3.13') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment