diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-06 11:40:49 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-12-06 11:40:49 +0900 |
| commit | dffb4d82dc83054eade20679f069979d242d9745 (patch) | |
| tree | fb8add0ee078d7b7463fa39a8d998835e0c8f71a | |
| parent | 3623a833a4304fc15ec78dbae17f25af906b44f2 (diff) | |
| download | mruby-dffb4d82dc83054eade20679f069979d242d9745.tar.gz mruby-dffb4d82dc83054eade20679f069979d242d9745.zip | |
Add type check for cls before allocation
| -rw-r--r-- | src/gc.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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 && |
