ruby-changes:51952
From: nobu <ko1@a...>
Date: Fri, 3 Aug 2018 15:31:28 +0900 (JST)
Subject: [ruby-changes:51952] nobu:r64167 (trunk): random.c: endless range random
nobu 2018-08-03 15:31:22 +0900 (Fri, 03 Aug 2018) New Revision: 64167 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64167 Log: random.c: endless range random * random.c (range_values): cannot determine the domain of an endless range. [ruby-core:88261] [Bug #14958] Modified files: trunk/random.c trunk/test/ruby/test_rand.rb Index: test/ruby/test_rand.rb =================================================================== --- test/ruby/test_rand.rb (revision 64166) +++ test/ruby/test_rand.rb (revision 64167) @@ -399,6 +399,7 @@ END https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rand.rb#L399 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]') Index: random.c =================================================================== --- random.c (revision 64166) +++ random.c (revision 64167) @@ -302,6 +302,7 @@ VALUE rb_cRandom; https://github.com/ruby/ruby/blob/trunk/random.c#L302 #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, VA https://github.com/ruby/ruby/blob/trunk/random.c#L1164 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, VA https://github.com/ruby/ruby/blob/trunk/random.c#L1207 } } -NORETURN(static void domain_error(void)); static void domain_error(void) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/