diff options
-rw-r--r-- | random.c | 3 | ||||
-rw-r--r-- | test/ruby/test_rand.rb | 1 |
2 files changed, 3 insertions, 1 deletions
@@ -302,6 +302,7 @@ VALUE rb_cRandom; #define id_minus '-' #define id_plus '+' static ID id_rand, id_bytes; +NORETURN(static void domain_error(void)); /* :nodoc: */ static void @@ -1163,6 +1164,7 @@ range_values(VALUE vmax, VALUE *begp, VALUE *endp, int *exclp) if (!rb_range_values(vmax, begp, &end, exclp)) return Qfalse; if (endp) *endp = end; + if (NIL_P(end)) domain_error(); if (!rb_respond_to(end, id_minus)) return Qfalse; r = rb_funcallv(end, id_minus, 1, begp); if (NIL_P(r)) return Qfalse; @@ -1205,7 +1207,6 @@ rand_int(VALUE obj, rb_random_t *rnd, VALUE vmax, int restrictive) } } -NORETURN(static void domain_error(void)); static void domain_error(void) { diff --git a/test/ruby/test_rand.rb b/test/ruby/test_rand.rb index 136ee4f912..ab9a1837f6 100644 --- a/test/ruby/test_rand.rb +++ b/test/ruby/test_rand.rb @@ -399,6 +399,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..)} r = Random.new(0) assert_in_delta(1.5488135039273248, r.rand(1.0...2.0), 0.0001, '[ruby-core:24655]') |