diff options
-rw-r--r-- | random.c | 6 | ||||
-rw-r--r-- | test/ruby/test_rand.rb | 1 |
2 files changed, 5 insertions, 2 deletions
@@ -1043,9 +1043,11 @@ random_s_bytes(VALUE obj, VALUE len) static VALUE range_values(VALUE vmax, VALUE *begp, VALUE *endp, int *exclp) { - VALUE end; + VALUE beg, end; - if (!rb_range_values(vmax, begp, &end, exclp)) return Qfalse; + if (!rb_range_values(vmax, &beg, &end, exclp)) return Qfalse; + if (begp) *begp = beg; + if (NIL_P(beg)) return Qnil; if (endp) *endp = end; if (NIL_P(end)) return Qnil; return rb_check_funcall_default(end, id_minus, 1, begp, Qfalse); diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index ab9a1837f6..939d17bdf7 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -400,6 +400,7 @@ END assert_raise(Errno::EDOM, Errno::ERANGE) { r.rand(1.0 / 0.0) } assert_raise(Errno::EDOM, Errno::ERANGE) { r.rand(0.0 / 0.0) } assert_raise(Errno::EDOM) {r.rand(1..)} + assert_raise(Errno::EDOM) {r.rand(..1)} r = Random.new(0) assert_in_delta(1.5488135039273248, r.rand(1.0...2.0), 0.0001, '[ruby-core:24655]') |