From 555035a349bb9d7659317dc65dc68ce6e2e6aaa7 Mon Sep 17 00:00:00 2001 From: nagachika Date: Tue, 7 May 2013 16:49:01 +0000 Subject: merge revision(s) 40208: [Backport #8380] * internal.h (MUL_OVERFLOW_SIGNED_INTEGER_P): New macro. (MUL_OVERFLOW_FIXNUM_P): Ditto. (MUL_OVERFLOW_LONG_P): Ditto. * array.c (rb_ary_product): Don't overflow on signed integer multiplication. * numeric.c (fix_mul): Ditto. (int_pow): Ditto. * rational.c (f_imul): Ditto. * insns.def (opt_mult): Ditto. * thread.c (sleep_timeval): Don't overflow on signed integer addition. * bignum.c (rb_int2big): Don't overflow on signed integer negation. (rb_big2ulong): Ditto. (rb_big2long): Ditto. (rb_big2ull): Ditto. (rb_big2ll): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@40602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- internal.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'internal.h') diff --git a/internal.h b/internal.h index e66b5fd038..6c80427dce 100644 --- a/internal.h +++ b/internal.h @@ -19,6 +19,15 @@ extern "C" { #endif #endif +#define MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, min, max) ( \ + (a) == 0 ? 0 : \ + (a) == -1 ? (b) < -(max) : \ + (a) > 0 ? \ + ((b) > 0 ? (max) / (a) < (b) : (min) / (a) > (b)) : \ + ((b) > 0 ? (min) / (a) < (b) : (max) / (a) > (b))) +#define MUL_OVERFLOW_FIXNUM_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, FIXNUM_MIN, FIXNUM_MAX) +#define MUL_OVERFLOW_LONG_P(a, b) MUL_OVERFLOW_SIGNED_INTEGER_P(a, b, LONG_MIN, LONG_MAX) + struct rb_deprecated_classext_struct { char conflict[sizeof(VALUE) * 3]; }; -- cgit v1.2.3