mruby-struct (struct_index): avoid direct array indexing

Caused crash probably due to the combination of C++ UB & optimizer.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-12-10 08:00:31 +09:00
parent 990d41f9f7
commit 38c50b3094
+2 -1
View File
@@ -393,7 +393,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)
{
return RSTRUCT_PTR(s)[struct_index(mrb, i, RSTRUCT_LEN(s))];
mrb_int idx = struct_index(mrb, i, RSTRUCT_LEN(s));
return RSTRUCT_PTR(s)[idx];
}
/* 15.2.18.4.2 */