numeric.c: fix a bug in left shift of negative integer.

`-1 * (1<<63)` causes overflow, but `-1<<63` is a valid value.
parent 9b3b2a4c
...@@ -1332,10 +1332,13 @@ mrb_num_shift(mrb_state *mrb, mrb_int val, mrb_int width, mrb_int *num) ...@@ -1332,10 +1332,13 @@ mrb_num_shift(mrb_state *mrb, mrb_int val, mrb_int width, mrb_int *num)
} }
else { else {
if ((width > NUMERIC_SHIFT_WIDTH_MAX) || if ((width > NUMERIC_SHIFT_WIDTH_MAX) ||
(val <= (MRB_INT_MIN >> width))) { (val < (MRB_INT_MIN >> width))) {
return FALSE; 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; return TRUE;
} }
......
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