mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Bugfix lshift() bit overflow; close #3023
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
22464fe5a0
commit
a4d5588101
+2
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user