Permalink
Browse files

Add type check for cls before allocation

  • Loading branch information...
matz committed Dec 6, 2016
1 parent 3623a83 commit dffb4d82dc83054eade20679f069979d242d9745
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/gc.c
View
@@ -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 &&

0 comments on commit dffb4d8

Please sign in to comment.