Skip to content
Browse files

check if an Exception instance has a "mesg" attribute

fix the issue that "Exception.new.inspect" causes SIGSEGV.
  • Loading branch information...
1 parent 3a49dfd commit 7a7f267b88904743278dc265fbecd46964ff1570 @tsahara tsahara committed Sep 12, 2012
Showing with 9 additions and 3 deletions.
  1. +6 −3 src/error.c
  2. +3 −0 test/t/exception.rb
View
9 src/error.c
@@ -134,20 +134,23 @@ exc_inspect(mrb_state *mrb, mrb_value exc)
mrb_str_cat2(mrb, str, ":");
mrb_str_append(mrb, str, line);
mrb_str_cat2(mrb, str, ": ");
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_append(mrb, str, mesg);
mrb_str_cat2(mrb, str, " (");
}
mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ")");
}
}
else {
str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc));
- if (RSTRING_LEN(mesg) > 0) {
+ if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) {
mrb_str_cat2(mrb, str, ": ");
mrb_str_append(mrb, str, mesg);
+ } else {
+ mrb_str_cat2(mrb, str, ": ");
+ mrb_str_cat2(mrb, str, mrb_obj_classname(mrb, exc));
}
}
return str;
View
3 test/t/exception.rb
@@ -269,3 +269,6 @@ def exception_test14
a == :ok
end
+assert('Exception#inspect without message') do
+ Exception.new.inspect
+end

0 comments on commit 7a7f267

Please sign in to comment.
Something went wrong with that request. Please try again.