mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
array.c: add recursion detection to Array#== and Array#eql?
Prevent SystemStackError when comparing arrays with circular references. Uses the same recursion detection mechanism as Hash equality methods. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
+10
@@ -1669,6 +1669,11 @@ mrb_ary_eq(mrb_state *mrb, mrb_value ary1)
|
||||
if (n == 1) return mrb_true_value();
|
||||
if (n == 0) return mrb_false_value();
|
||||
|
||||
/* Check for recursion */
|
||||
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_OPSYM(eq), ary1, ary2)) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
for (mrb_int i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
mrb_value eq = mrb_funcall_id(mrb, mrb_ary_entry(ary1, i), MRB_OPSYM(eq), 1, mrb_ary_entry(ary2, i));
|
||||
@@ -1695,6 +1700,11 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
|
||||
if (n == 1) return mrb_true_value();
|
||||
if (n == 0) return mrb_false_value();
|
||||
|
||||
/* Check for recursion */
|
||||
if (MRB_RECURSIVE_BINARY_P(mrb, MRB_SYM_Q(eql), ary1, ary2)) {
|
||||
return mrb_false_value();
|
||||
}
|
||||
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
for (mrb_int i=0; i<RARRAY_LEN(ary1); i++) {
|
||||
mrb_value eq = mrb_funcall_id(mrb, mrb_ary_entry(ary1, i), MRB_SYM_Q(eql), 1, mrb_ary_entry(ary2, i));
|
||||
|
||||
Reference in New Issue
Block a user