summaryrefslogtreecommitdiffhomepage
path: root/src/numeric.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-07-05 03:07:44 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-07-05 03:11:39 +0900
commitcc01dedc656e77f2b81902fe703537e39776a6ca (patch)
tree9b11956037b6ae88f686508b22555663f144ee7a /src/numeric.c
parentc377d504f68e44f719f8314b1492b86409b1289c (diff)
downloadmruby-cc01dedc656e77f2b81902fe703537e39776a6ca.tar.gz
mruby-cc01dedc656e77f2b81902fe703537e39776a6ca.zip
Avoid undefined behavior of left shifting negative integer; #3728
Diffstat (limited to 'src/numeric.c')
-rw-r--r--src/numeric.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/numeric.c b/src/numeric.c
index 6c9875719..41c4678d3 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -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;