summaryrefslogtreecommitdiffhomepage
path: root/src/error.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-04-25 10:39:11 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-04-25 10:41:50 +0900
commit88cd807379152ea3fec5f534e5f4d6ebebd53982 (patch)
treef6b27a76821b8b92f6fc474ce56aab5795afb51b /src/error.c
parent03cdb8e9dd3447115530418c2b8183c94dee2a53 (diff)
downloadmruby-88cd807379152ea3fec5f534e5f4d6ebebd53982.tar.gz
mruby-88cd807379152ea3fec5f534e5f4d6ebebd53982.zip
Avoid use of `snprintf()` when DISABLE_STDIO is set; fix #3632
ref #3492 #3515 #3517
Diffstat (limited to 'src/error.c')
-rw-r--r--src/error.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/error.c b/src/error.c
index ac11e4d8d..258a8f7df 100644
--- a/src/error.c
+++ b/src/error.c
@@ -137,6 +137,7 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
{
mrb_value str, mesg, file, line;
mrb_bool append_mesg;
+ const char *cname;
mesg = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "mesg"));
file = mrb_attr_get(mrb, exc, mrb_intern_lit(mrb, "file"));
@@ -148,28 +149,18 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
append_mesg = RSTRING_LEN(mesg) > 0;
}
+ cname = mrb_obj_classname(mrb, exc);
+ str = mrb_str_new_cstr(mrb, cname);
if (mrb_string_p(file) && mrb_fixnum_p(line)) {
- char buf[32];
-
- str = mrb_str_dup(mrb, file);
- snprintf(buf, sizeof(buf), ":%" MRB_PRId ": ", mrb_fixnum(line));
- mrb_str_cat_cstr(mrb, str, buf);
if (append_mesg) {
- mrb_str_cat_str(mrb, str, mesg);
- mrb_str_cat_lit(mrb, str, " (");
+ str = mrb_format(mrb, "%S:%S:%S (%S)", file, line, mesg, str);
}
- mrb_str_cat_cstr(mrb, str, mrb_obj_classname(mrb, exc));
- if (append_mesg) {
- mrb_str_cat_lit(mrb, str, ")");
+ else {
+ str = mrb_format(mrb, "%S:%S:%S", file, line, str);
}
}
- else {
- const char *cname = mrb_obj_classname(mrb, exc);
- str = mrb_str_new_cstr(mrb, cname);
- if (append_mesg) {
- mrb_str_cat_lit(mrb, str, ": ");
- mrb_str_cat_str(mrb, str, mesg);
- }
+ else if (append_mesg) {
+ str = mrb_format(mrb, "%S:%S", str, mesg);
}
return str;
}