mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Avoid undefined behavior of left shifting negative integer; #3728
This commit is contained in:
+2
-2
@@ -962,16 +962,16 @@ lshift(mrb_state *mrb, mrb_int val, mrb_int width)
|
||||
(val > (MRB_INT_MAX >> width))) {
|
||||
goto bit_overflow;
|
||||
}
|
||||
return mrb_fixnum_value(val << width);
|
||||
}
|
||||
else {
|
||||
if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
|
||||
(val < (MRB_INT_MIN >> width))) {
|
||||
goto bit_overflow;
|
||||
}
|
||||
return mrb_fixnum_value(val * (1u << width));
|
||||
}
|
||||
|
||||
return mrb_fixnum_value(val << width);
|
||||
|
||||
bit_overflow:
|
||||
{
|
||||
mrb_float f = (mrb_float)val;
|
||||
|
||||
Reference in New Issue
Block a user