summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-20 03:28:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-20 03:28:34 +0000
commit6523eee836cc3253253fd5a814c6784cd8b8c99c (patch)
tree10e71e5b0d14150aa4a76b2415e431572565f584 /array.c
parentf78380f0f1e4941119bef7661eb7b0afe2df089c (diff)
* array.c (rb_ary_sample): get rid of infinite loop. #455
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18718 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/array.c b/array.c
index 0b7427cf91..d3dbde40d8 100644
--- a/array.c
+++ b/array.c
@@ -3032,8 +3032,9 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
return RARRAY_PTR(ary)[i];
}
rb_scan_args(argc, argv, "1", &nv);
- if (len == 0) return rb_ary_new2(0);
n = NUM2INT(nv);
+ if (n > len) n = len;
+ if (n == 0) return rb_ary_new2(0);
result = rb_ary_new2(n);
for (i=0; i<n; i++) {
retry: