From dd3ed8d99c2540e87bd27364b1b911de9a5fc7d6 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 14 Nov 2020 20:40:06 +0900 Subject: Allow full `mrb_int` operations in overflow detection. Fix overflow detection in integer operations with `MRB_WORD_BOXING`. This bug made `1073741824 == 1073741824+0` to be `false` on 32bit platforms. --- include/mruby/numeric.h | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/mruby/numeric.h b/include/mruby/numeric.h index 7e70b9dee..9d9ccb342 100644 --- a/include/mruby/numeric.h +++ b/include/mruby/numeric.h @@ -70,32 +70,24 @@ MRB_API mrb_value mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y); #ifdef MRB_HAVE_TYPE_GENERIC_CHECKED_ARITHMETIC_BUILTINS -#ifndef MRB_WORD_BOXING -# define WBCHK(x) 0 -#else -# define WBCHK(x) !FIXABLE(x) -#endif - static inline mrb_bool mrb_int_add_overflow(mrb_int augend, mrb_int addend, mrb_int *sum) { - return __builtin_add_overflow(augend, addend, sum) || WBCHK(*sum); + return __builtin_add_overflow(augend, addend, sum); } static inline mrb_bool mrb_int_sub_overflow(mrb_int minuend, mrb_int subtrahend, mrb_int *difference) { - return __builtin_sub_overflow(minuend, subtrahend, difference) || WBCHK(*difference); + return __builtin_sub_overflow(minuend, subtrahend, difference); } static inline mrb_bool mrb_int_mul_overflow(mrb_int multiplier, mrb_int multiplicand, mrb_int *product) { - return __builtin_mul_overflow(multiplier, multiplicand, product) || WBCHK(*product); + return __builtin_mul_overflow(multiplier, multiplicand, product); } -#undef WBCHK - #else #define MRB_UINT_MAKE2(n) uint ## n ## _t -- cgit v1.2.3