diff --git a/include/picrin/proc.h b/include/picrin/proc.h index 7d6dcd92..c29b6c36 100644 --- a/include/picrin/proc.h +++ b/include/picrin/proc.h @@ -19,6 +19,8 @@ struct pic_proc { pic_value aux; }; +#define pic_proc_p(o) (pic_type(o) == PIC_TT_PROC) + #define pic_proc_ptr(o) ((struct pic_proc *)(o).u.data) #define pic_proc_cfunc_p(o) (pic_proc_ptr(o)->cfunc_p) diff --git a/src/vm.c b/src/vm.c index 1dc31bf7..1e2bb2b3 100644 --- a/src/vm.c +++ b/src/vm.c @@ -224,6 +224,10 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args) struct pic_proc *proc; c = pic->sp[-pc->u.i]; + if (! pic_proc_p(c)) { + pic->errmsg = "invalid application"; + goto L_RAISE; + } proc = pic_proc_ptr(c); ci = PUSHCI();