1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2018-08-03 06:31:22 +00:00
parent 4cef2c8d6b
commit 64712906b0
2 changed files with 3 additions and 1 deletions

View file

@ -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)
{

View file

@ -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]')