mruby-struct/struct.c (struct_aref_int): update index check

Check should use the number of members, not the actual size of the
struct object, which may be smaller than the declared size.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-05-25 08:40:46 +09:00
parent 8e579e6552
commit 0295e6a688
+2 -1
View File
@@ -399,7 +399,8 @@ struct_index(mrb_state *mrb, mrb_int i, mrb_int len)
static mrb_value
struct_aref_int(mrb_state *mrb, mrb_value s, mrb_int i)
{
mrb_int idx = struct_index(mrb, i, RSTRUCT_LEN(s));
mrb_int idx = struct_index(mrb, i, num_members(mrb, s));
if (idx >= RSTRUCT_LEN(s)) return mrb_nil_value();
return RSTRUCT_PTR(s)[idx];
}