summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-18 14:18:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-05-18 14:18:02 +0000
commit7313b14021413a38f49d26da8640571e52220fc3 (patch)
tree4881ed200f66c76350f4c0a44cbdfbf96b08969c /array.c
parent642273c070f6121c0ad3f24752b7b91fd63670c3 (diff)
* array.c (rb_ary_first): add negative length check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/array.c b/array.c
index e2bbf2b..91c298d 100644
--- a/array.c
+++ b/array.c
@@ -748,10 +748,15 @@ rb_ary_first(argc, argv, ary)
return RARRAY(ary)->ptr[0];
}
else {
- VALUE n;
+ VALUE nv;
+ long n;
- rb_scan_args(argc, argv, "01", &n);
- return rb_ary_subseq(ary, 0, NUM2LONG(n));
+ rb_scan_args(argc, argv, "01", &nv);
+ n = NUM2LONG(nv);
+ if (n < 0) {
+ rb_raise(rb_eArgError, "negative array size");
+ }
+ return rb_ary_subseq(ary, 0, n);
}
}