diff options
-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 |