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

Random.urandom raises an exception instead of returning nil when failed

Early failure looks better in this case.  Refs [Bugs #13885].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59858 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2017-09-12 13:57:36 +00:00
parent d0cdb26c75
commit d212f11a00

View file

@ -624,7 +624,8 @@ random_raw_seed(VALUE self, VALUE size)
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;
}