Skip to content

Commit 5f03767

Browse files
committed
mruby: bbsruby.c: print_exception(): Fix crash on printing exceptions with empty backtrace`, e.g., syntax error exceptions.
1 parent ff98de6 commit 5f03767

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

bbsruby.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,18 @@ void print_exception RB_PV((void))
803803
outs(buffer);
804804
outs("\n");
805805
VALUE ary = CMRB_C(rb_funcallv, mrb_funcall_argv)(exception, CMRB_C(rb_intern, mrb_intern_cstr)("backtrace"), 0, NULL);
806-
int c;
807-
for (c=0; c < RARRAY_LEN(ary); c++)
806+
#ifdef BBSRUBY_USE_MRUBY
807+
// Some `Exception` objects have theirs `backtrace` unset in mruby
808+
if (mrb_array_p(ary))
809+
#endif
808810
{
809-
outs(" from: ");
810-
outs(StringValueCStr(RARRAY_PTR(ary)[c]));
811-
outs("\n");
811+
int c;
812+
for (c=0; c < RARRAY_LEN(ary); c++)
813+
{
814+
outs(" from: ");
815+
outs(StringValueCStr(RARRAY_PTR(ary)[c]));
816+
outs("\n");
817+
}
812818
}
813819
out_footer(" (發生錯誤)", "按任意鍵返回");
814820
}

0 commit comments

Comments
 (0)