ruby-changes:47741
From: mame <ko1@a...>
Date: Tue, 12 Sep 2017 22:57:40 +0900 (JST)
Subject: [ruby-changes:47741] mame:r59858 (trunk): Random.urandom raises an exception instead of returning nil when failed
mame 2017-09-12 22:57:36 +0900 (Tue, 12 Sep 2017) New Revision: 59858 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59858 Log: Random.urandom raises an exception instead of returning nil when failed Early failure looks better in this case. Refs [Bugs #13885]. Modified files: trunk/random.c Index: random.c =================================================================== --- random.c (revision 59857) +++ random.c (revision 59858) @@ -624,7 +624,8 @@ random_raw_seed(VALUE self, VALUE size) https://github.com/ruby/ruby/blob/trunk/random.c#L624 long n = NUM2ULONG(size); VALUE buf = rb_str_new(0, n); if (n == 0) return buf; - if (fill_random_bytes(RSTRING_PTR(buf), n, FALSE)) return Qnil; + if (fill_random_bytes(RSTRING_PTR(buf), n, FALSE)) + rb_raise(rb_eRuntimeError, "failed to get urandom"); return buf; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/