summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-11-16 01:29:04 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-11-16 01:29:04 +0900
commit739dad6e87e91c74cda794ae3f33cd94a7c33eb1 (patch)
tree04efbd14bcc5463fc2a8f7975f2ef9623715f954 /include
parent4f6cce059b317f7e6c1da801fe0edd487985df6e (diff)
downloadmruby-739dad6e87e91c74cda794ae3f33cd94a7c33eb1.tar.gz
mruby-739dad6e87e91c74cda794ae3f33cd94a7c33eb1.zip
Fixed a memory problem in Array#to_h
Reported from Alex Snaps via Mathieu Leduc-Hamel, both from shopify.com. Thank you!
Diffstat (limited to 'include')
-rw-r--r--include/mruby/array.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/mruby/array.h b/include/mruby/array.h
index bd78db066..8f9d5d502 100644
--- a/include/mruby/array.h
+++ b/include/mruby/array.h
@@ -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 */