Add type check for cls before allocation

This commit is contained in:
Yukihiro "Matz" Matsumoto
2016-12-06 11:40:49 +09:00
parent 3623a833a4
commit dffb4d82dc
+12 -1
View File
@@ -480,7 +480,18 @@ mrb_obj_alloc(mrb_state *mrb, enum mrb_vtype ttype, struct RClass *cls)
mrb_gc *gc = &mrb->gc;
if (cls) {
enum mrb_vtype tt = MRB_INSTANCE_TT(cls);
enum mrb_vtype tt;
switch (cls->tt) {
case MRB_TT_CLASS:
case MRB_TT_SCLASS:
case MRB_TT_MODULE:
case MRB_TT_ENV:
break;
default:
mrb_raise(mrb, E_TYPE_ERROR, "allocation failure");
}
tt = MRB_INSTANCE_TT(cls);
if (tt != MRB_TT_FALSE &&
ttype != MRB_TT_SCLASS &&
ttype != MRB_TT_ICLASS &&