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:
parent
d0cdb26c75
commit
d212f11a00
1 changed files with 2 additions and 1 deletions
3
random.c
3
random.c
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue