aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_numeric.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-28 04:59:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-28 04:59:49 +0000
commita4a551f85658c90de5723b9d0f7e06c87a0e6378 (patch)
tree1dee13eb1ccd7b568b112527b6181f00ef49b680 /test/ruby/test_numeric.rb
parentd596ba8dc032335fd89491951297802c3aeb66a1 (diff)
downloadruby-a4a551f85658c90de5723b9d0f7e06c87a0e6378.tar.gz
numeric.c: integer overflow
* numeric.c (ruby_num_interval_step_size): get rid of integer overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45212 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_numeric.rb')
-rw-r--r--test/ruby/test_numeric.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 90d4d9ffea..0c9c38610c 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -251,7 +251,8 @@ class TestNumeric < Test::Unit::TestCase
end
def test_step
- bignum = 1 << 100
+ i, bignum = 32, 1 << 30
+ bignum <<= (i <<= 1) - 32 until bignum.is_a?(Bignum)
assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
assert_raise(ArgumentError) { 1.step(10, 0) { } }
@@ -267,6 +268,9 @@ class TestNumeric < Test::Unit::TestCase
assert_nothing_raised { 1.step(by: nil) }
assert_nothing_raised { 1.step(by: nil).size }
+ assert_equal(bignum*2+1, (-bignum).step(bignum, 1).size)
+ assert_equal(bignum*2, (-bignum).step(bignum-1, 1).size)
+
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10]
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10]
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10, by: nil]