Fixed a memory problem in Array#to_h

Reported from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
This commit is contained in:
Yukihiro "Matz" Matsumoto
2016-11-16 01:29:04 +09:00
parent 4f6cce059b
commit 739dad6e87
4 changed files with 21 additions and 10 deletions
+9
View File
@@ -134,6 +134,15 @@ mrb_ary_len(mrb_state *mrb, mrb_value ary)
return RARRAY_LEN(ary);
}
static inline mrb_value
ary_elt(mrb_value ary, mrb_int offset)
{
if (offset < 0 || RARRAY_LEN(ary) <= offset) {
return mrb_nil_value();
}
return RARRAY_PTR(ary)[offset];
}
MRB_END_DECL
#endif /* MRUBY_ARRAY_H */