Skip to content

Commit

Permalink
Add type check for cls before allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Dec 6, 2016
1 parent 3623a83 commit dffb4d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit dffb4d8

Please sign in to comment.