From 0295e6a6886cb46cd89e8ec517599d1ae40d8a5e Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 25 May 2023 08:40:46 +0900 Subject: [PATCH] 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. --- mrbgems/mruby-struct/src/struct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 6aea137e0..98171755a 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -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]; }