summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 06:31:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-03 06:31:22 +0000
commit64712906b063d5470f74ef0b19d16e4aa84defdf (patch)
tree54c0eaa1d886580539e070806ef970bf59649612
parent4cef2c8d6b61cc517191da781f777306823a05cb (diff)
random.c: endless range random
* random.c (range_values): cannot determine the domain of an endless range. [ruby-core:88261] [Bug #14958] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--random.c3
-rw-r--r--test/ruby/test_rand.rb1
2 files changed, 3 insertions, 1 deletions
diff --git a/random.c b/random.c
index 7165f3c4a3..75ad5ff5bd 100644
--- a/random.c
+++ b/random.c
@@ -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]')