summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2012-07-28 16:01:58 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2012-07-28 16:01:58 -0700
commit5ed89a401c72e521806fef6143e12f77c16bf8b7 (patch)
tree45765f5489aa228f4e461d75ff883664835a23ab /src
parent919a84771bfb9d535d56d68a49e60567ecda2253 (diff)
parenta2aa7e7f520b42a2de393039bd8d468dbd299026 (diff)
downloadmruby-5ed89a401c72e521806fef6143e12f77c16bf8b7.tar.gz
mruby-5ed89a401c72e521806fef6143e12f77c16bf8b7.zip
Merge pull request #399 from akuroda/array_first_fix
fix segmentation fault in Array#first
Diffstat (limited to 'src')
-rw-r--r--src/array.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/array.c b/src/array.c
index 0f52c38ef..ccd22674e 100644
--- a/src/array.c
+++ b/src/array.c
@@ -764,6 +764,9 @@ mrb_ary_first(mrb_state *mrb, mrb_value self)
if (mrb_get_args(mrb, "|i", &size) == 0) {
return (a->len > 0)? a->ptr[0]: mrb_nil_value();
}
+ if (size < 0) {
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "negative array size");
+ }
if (size > a->len) size = a->len;
if (a->flags & MRB_ARY_SHARED) {