summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 03:46:47 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-22 03:46:47 (GMT)
commit3f2ce6373f7902e02c559876fb7255b5e36aaa64 (patch)
tree685108cad30bda565d1bd67f803546686f077691 /random.c
parente51a9b49f1ded288ee00732f0d7d4af01764a793 (diff)
random.c: fix error message
* random.c (rb_random_ulong_limited): fix error message for negative value. [ruby-dev:47061] [Bug #7903] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39376 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r--random.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/random.c b/random.c
index 6e635d9..9b62cc1 100644
--- a/random.c
+++ b/random.c
@@ -947,9 +947,13 @@ rb_random_ulong_limited(VALUE obj, unsigned long limit)
{
rb_random_t *rnd = try_get_rnd(obj);
if (!rnd) {
+ extern int rb_num_negative_p(VALUE);
VALUE lim = ULONG2NUM(limit);
VALUE v = rb_funcall2(obj, id_rand, 1, &lim);
unsigned long r = NUM2ULONG(v);
+ if (rb_num_negative_p(v)) {
+ rb_raise(rb_eRangeError, "random number too small %ld", r);
+ }
if (r > limit) {
rb_raise(rb_eRangeError, "random number too big %ld", r);
}