1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Fix overflow detection for LLP64 arch [Bug #13748]

FIXNUMs are expected to fit into a long type, but the test is about a
VALUE type. Since long is < than VALUE on LLP64, the overflow is not
detected. As a result "2**31" evaluates to "-2147483648" on Windows with
gcc-7.1.0.
patched by Lars Kanis <lars@greiz-reinsdorf.de>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2017-09-25 08:19:10 +00:00
parent 2c644a50ce
commit c04b6232f8

View file

@ -115,7 +115,7 @@ extern "C" {
/* __builtin_mul_overflow_p can take bitfield */ /* __builtin_mul_overflow_p can take bitfield */
/* and GCC permits bitfields for integers other than int */ /* and GCC permits bitfields for integers other than int */
#define MUL_OVERFLOW_FIXNUM_P(a, b) ({ \ #define MUL_OVERFLOW_FIXNUM_P(a, b) ({ \
struct { SIGNED_VALUE fixnum : SIZEOF_VALUE * CHAR_BIT - 1; } c; \ struct { long fixnum : SIZEOF_LONG * CHAR_BIT - 1; } c; \
__builtin_mul_overflow_p((a), (b), c.fixnum); \ __builtin_mul_overflow_p((a), (b), c.fixnum); \
}) })
#else #else