diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-14 20:40:06 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-14 20:40:06 +0900 |
| commit | dd3ed8d99c2540e87bd27364b1b911de9a5fc7d6 (patch) | |
| tree | b82c5b7115552da995373f0312503da38ea43b16 /include | |
| parent | 19450df41e53e52260c233cfa026ba841c8a4ca0 (diff) | |
| download | mruby-dd3ed8d99c2540e87bd27364b1b911de9a5fc7d6.tar.gz mruby-dd3ed8d99c2540e87bd27364b1b911de9a5fc7d6.zip | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/numeric.h | 14 |
1 files changed, 3 insertions, 11 deletions
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 |
