aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/array.c b/array.c
index 198f0570f1..4eeae43391 100644
--- a/array.c
+++ b/array.c
@@ -3450,6 +3450,7 @@ rb_ary_sample(int argc, VALUE *argv, VALUE ary)
}
rb_scan_args(argc, argv, "1", &nv);
n = NUM2LONG(nv);
+ if (n < 0) rb_raise(rb_eArgError, "negative sample number");
ptr = RARRAY_PTR(ary);
len = RARRAY_LEN(ary);
if (n > len) n = len;