iv_foreach() needs to update the pointer at each loop

When calling a user function, a pointer retrieved outside of a loop may be invalidated.
This commit is contained in:
dearblue
2025-06-19 22:25:13 +09:00
parent 2edfd96cbe
commit afd5805224
+2 -2
View File
@@ -187,9 +187,9 @@ static void
iv_foreach(mrb_state *mrb, iv_tbl *t, mrb_iv_foreach_func *func, void *p)
{
if (t == NULL || t->alloc == 0 || t->size == 0) return;
mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc];
mrb_value *vals = t->ptr;
for (int i = 0; i < t->size; i++) {
mrb_sym *keys = (mrb_sym*)&t->ptr[t->alloc];
mrb_value *vals = t->ptr;
if ((*func)(mrb, keys[i], vals[i], p) != 0) return;
}
}