Makes mrb_any_to_s() accept an object whose class is NULL

When using `mrb_any_to_s()` for debugging purposes, giving an object
whose class is `NULL` no longer causes a SIGSEGV and no crash.
This is achieved by making `mrb_class_name()` and `mrb_str_cat_cstr()`
null safe.
This commit is contained in:
dearblue
2020-04-29 16:57:25 +09:00
parent e2ac2a82a5
commit 49b2e8c3a9
2 changed files with 5 additions and 2 deletions
+4 -1
View File
@@ -1728,7 +1728,10 @@ mrb_class_real(struct RClass* cl)
MRB_API const char*
mrb_class_name(mrb_state *mrb, struct RClass* c)
{
mrb_value name = class_name_str(mrb, c);
mrb_value name;
if (c == NULL) return NULL;
name = class_name_str(mrb, c);
return RSTRING_PTR(name);
}
+1 -1
View File
@@ -2759,7 +2759,7 @@ mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len)
MRB_API mrb_value
mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr)
{
return mrb_str_cat(mrb, str, ptr, strlen(ptr));
return mrb_str_cat(mrb, str, ptr, ptr ? strlen(ptr) : 0);
}
MRB_API mrb_value