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
3
random.c
3
random.c
@ -624,7 +624,8 @@ random_raw_seed(VALUE self, VALUE size)
|
|||||||
long n = NUM2ULONG(size);
|
long n = NUM2ULONG(size);
|
||||||
VALUE buf = rb_str_new(0, n);
|
VALUE buf = rb_str_new(0, n);
|
||||||
if (n == 0) return buf;
|
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;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user