diff options
| author | U.Nakamura <usa@ruby-lang.org> | 2023-06-19 20:21:40 +0900 |
|---|---|---|
| committer | U.Nakamura <usa@ruby-lang.org> | 2023-06-19 20:21:40 +0900 |
| commit | 344249674f7a7835445a44695664897fa4b83f00 (patch) | |
| tree | 8b01aa0583249abea8b50ad8093ca507a0059a71 /test/ruby | |
| parent | e031f2b4c7be8854f424cfc692f7ce27213abdd2 (diff) | |
merge revision(s) 1cdf8ab07b24ebd16e93621957196e8b1d67f2ba: [Backport #19323]
[Bug #19323] Raise `RangeError` instead of integer overflow
---
bignum.c | 5 ++++-
test/ruby/test_integer.rb | 18 ++++++++----------
2 files changed, 12 insertions(+), 11 deletions(-)
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_integer.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index a2b181c642..2f3f00ecda 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -2,16 +2,9 @@ require 'test/unit' class TestInteger < Test::Unit::TestCase - BDSIZE = 0x4000000000000000.coerce(0)[0].size - def self.bdsize(x) - ((x + 1) / 8 + BDSIZE) / BDSIZE * BDSIZE - end - def bdsize(x) - self.class.bdsize(x) - end - FIXNUM_MIN = RbConfig::LIMITS['FIXNUM_MIN'] FIXNUM_MAX = RbConfig::LIMITS['FIXNUM_MAX'] + LONG_MAX = RbConfig::LIMITS['LONG_MAX'] def test_aref @@ -96,11 +89,16 @@ class TestInteger < Test::Unit::TestCase assert_equal(0, 1 << -0x40000001) assert_equal(0, 1 << -0x80000000) assert_equal(0, 1 << -0x80000001) - # assert_equal(bdsize(0x80000000), (1 << 0x80000000).size) + + char_bit = RbConfig::LIMITS["UCHAR_MAX"].bit_length + size_max = RbConfig::LIMITS["SIZE_MAX"] + size_bit_max = size_max * char_bit + assert_raise_with_message(RangeError, /shift width/) { + 1 << size_bit_max + } end def test_rshift - # assert_equal(bdsize(0x40000001), (1 >> -0x40000001).size) assert_predicate((1 >> 0x80000000), :zero?) assert_predicate((1 >> 0xffffffff), :zero?) assert_predicate((1 >> 0x100000000), :zero?) |
