summaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-21 14:47:02 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-05-21 14:47:02 +0000
commit08fc80ffe54d749c3657457eee7f23e0bbc471bc (patch)
tree7efc61d39580d58bb23212e5ba3a28e27b92a34a /array.c
parent6afe623d23ce3bec3a97d32c5156a0f01bcd7fcf (diff)
merges r23359 from trunk into ruby_1_9_1.
-- * array.c (rb_ary_sample): negative sample number is invalid. [ruby-core:23374] git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@23512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/array.c b/array.c
index bc342b586..330162160 100644
--- a/array.c
+++ b/array.c
@@ -3302,8 +3302,9 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
}
rb_scan_args(argc, argv, "1", &nv);
n = NUM2LONG(nv);
- ptr = RARRAY_PTR(ary);
- len = RARRAY_LEN(ary);
+ if (n < 0) rb_raise(rb_eArgError, "negative sample number");
+ ptr = RARRAY_PTR(ary);
+ len = RARRAY_LEN(ary);
if (n > len) n = len;
switch (n) {
case 0: return rb_ary_new2(0);