diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-27 07:10:53 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-10-27 07:10:53 +0000 |
commit | 723038b0ba1a6fac881ceacdfc0ff01375eedc10 (patch) | |
tree | 96788d9c79abd5583b6352506ffc26fb78124cdf | |
parent | e344d8a48388a213e4dd404b128769c5dccbf11a (diff) |
* bignum.c (rb_big_divide): raise ZeroDivisionError if divisor is
zero, as well as Fixnum. [ruby-core:40429] [Bug #5490]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | bignum.c | 4 | ||||
-rw-r--r-- | test/ruby/test_bignum.rb | 3 |
3 files changed, 11 insertions, 1 deletions
@@ -1,3 +1,8 @@ +Thu Oct 27 16:10:46 2011 Nobuyoshi Nakada <[email protected]> + + * bignum.c (rb_big_divide): raise ZeroDivisionError if divisor is + zero, as well as Fixnum. [ruby-core:40429] [Bug #5490] + Thu Oct 27 14:56:22 2011 Nobuyoshi Nakada <[email protected]> * configure.in (RUBY_FUNC_ATTRIBUTE): unset temporary variable. @@ -2774,7 +2774,9 @@ rb_big_divide(VALUE x, VALUE y, ID op) case T_FLOAT: { - double div = rb_big2dbl(x) / RFLOAT_VALUE(y); + double div, dy = RFLOAT_VALUE(y); + if (dy == 0.0) rb_num_zerodiv(); + div = rb_big2dbl(x) / dy; if (op == '/') { return DBL2NUM(div); } diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 5458f0cf4a..9256c7f3f4 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -272,6 +272,9 @@ class TestBignum < Test::Unit::TestCase assert_equal(T32.to_f, T32 / 1.0) assert_raise(TypeError) { T32 / "foo" } assert_equal(0x20000000, 0x40000001.div(2.0), "[ruby-dev:34553]") + bug5490 = '[ruby-core:40429]' + assert_raise(ZeroDivisionError, bug5490) {T1024.div(0)} + assert_raise(ZeroDivisionError, bug5490) {T1024.div(0.0)} end def test_idiv |