Skip to content

Commit

Permalink
Fix infinite recursive call bugs in integer division.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Mar 24, 2021
1 parent 3deb62d commit 98799aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mrbgems/mruby-complex/src/complex.c
Expand Up @@ -304,6 +304,7 @@ int_div(mrb_state *mrb, mrb_value x)
}
switch (mrb_type(y)) {
case MRB_TT_COMPLEX:
x = complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
default:
return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y));
Expand All @@ -323,6 +324,7 @@ int_quo(mrb_state *mrb, mrb_value x)

switch (mrb_type(y)) {
case MRB_TT_COMPLEX:
x = complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
default:
return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y));
Expand Down
2 changes: 2 additions & 0 deletions mrbgems/mruby-rational/src/rational.c
Expand Up @@ -428,6 +428,7 @@ int_div(mrb_state *mrb, mrb_value x)
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
#if defined(MRB_USE_COMPLEX)
case MRB_TT_COMPLEX:
x = mrb_complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
#endif
case MRB_TT_FLOAT:
Expand Down Expand Up @@ -460,6 +461,7 @@ int_quo(mrb_state *mrb, mrb_value x)
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
#if defined(MRB_USE_COMPLEX)
case MRB_TT_COMPLEX:
x = mrb_complex_new(mrb, (mrb_float)a, 0);
return mrb_funcall_id(mrb, x, MRB_OPSYM(div), 1, y);
#endif
default:
Expand Down

0 comments on commit 98799aa

Please sign in to comment.