summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-12 13:57:36 (GMT)
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-09-12 13:57:36 (GMT)
commitd212f11a004fb60534fc49374a1d5e159a14d710 (patch)
treedeec073f1e865cc52ccaee14e68146d16f1db905 /random.c
parentd0cdb26c75bb87e411bfa854279cc9db3561b9ec (diff)
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
Diffstat (limited to 'random.c')
-rw-r--r--random.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/random.c b/random.c
index 82a51cc..8ea3d77 100644
--- a/random.c
+++ b/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;
}