From 0f3930426515848be755c5480df354fa9e2109f4 Mon Sep 17 00:00:00 2001 From: cremno Date: Mon, 5 May 2014 15:24:22 +0200 Subject: add function for checked mrb_int addition --- src/numeric.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/numeric.c') diff --git a/src/numeric.c b/src/numeric.c index 56835edbf..8ea71ada6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -1109,9 +1109,7 @@ mrb_fixnum_plus(mrb_state *mrb, mrb_value x, mrb_value y) if (a == 0) return y; b = mrb_fixnum(y); - c = a + b; - if (((a < 0) ^ (b < 0)) == 0 && (a < 0) != (c < 0)) { - /* integer overflow */ + if (mrb_int_add_overflow(a, b, &c)) { return mrb_float_value(mrb, (mrb_float)a + (mrb_float)b); } return mrb_fixnum_value(c); -- cgit v1.2.3