mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
numeric.c: fix a bug in left shift of negative integer.
`-1 * (1<<63)` causes overflow, but `-1<<63` is a valid value.
This commit is contained in:
+5
-2
@@ -1332,10 +1332,13 @@ mrb_num_shift(mrb_state *mrb, mrb_int val, mrb_int width, mrb_int *num)
|
||||
}
|
||||
else {
|
||||
if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
|
||||
(val <= (MRB_INT_MIN >> width))) {
|
||||
(val < (MRB_INT_MIN >> width))) {
|
||||
return FALSE;
|
||||
}
|
||||
*num = val * ((mrb_int)1 << width);
|
||||
if (width == NUMERIC_SHIFT_WIDTH_MAX)
|
||||
*num = MRB_INT_MIN;
|
||||
else
|
||||
*num = val * ((mrb_int)1 << width);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user