error.c: the error message may contain `NUL` character.

parent 73798bff
...@@ -102,24 +102,24 @@ print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace) ...@@ -102,24 +102,24 @@ print_backtrace(mrb_state *mrb, struct RObject *exc, mrb_value backtrace)
mrb_int i; mrb_int i;
mrb_int n = RARRAY_LEN(backtrace); mrb_int n = RARRAY_LEN(backtrace);
mrb_value *loc, mesg; mrb_value *loc, mesg;
FILE *stream = stderr;
if (n != 0) { if (n != 0) {
if (n > 1) { if (n > 1) {
fprintf(stream, "trace (most recent call last):\n"); fprintf(stderr, "trace (most recent call last):\n");
} }
for (i=n-1,loc=&RARRAY_PTR(backtrace)[i]; i>0; i--,loc--) { for (i=n-1,loc=&RARRAY_PTR(backtrace)[i]; i>0; i--,loc--) {
if (mrb_string_p(*loc)) { if (mrb_string_p(*loc)) {
fprintf(stream, "\t[%d] %.*s\n", fprintf(stderr, "\t[%d] %.*s\n",
(int)i, (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc)); (int)i, (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
} }
} }
if (mrb_string_p(*loc)) { if (mrb_string_p(*loc)) {
fprintf(stream, "%.*s: ", (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc)); fprintf(stderr, "%.*s: ", (int)RSTRING_LEN(*loc), RSTRING_PTR(*loc));
} }
} }
mesg = mrb_exc_inspect(mrb, mrb_obj_value(exc)); mesg = mrb_exc_inspect(mrb, mrb_obj_value(exc));
fprintf(stream, "%.*s\n", (int)RSTRING_LEN(mesg), RSTRING_PTR(mesg)); fwrite(RSTRING_PTR(mesg), RSTRING_LEN(mesg), 1, stderr);
fputc('\n', stderr);
} }
/* mrb_print_backtrace /* mrb_print_backtrace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment