From 178cf109bd94e0bb96a7dd62a9bd2f3b54931038 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Sun, 13 Dec 2009 16:59:20 +0900 Subject: [PATCH] fixing segfault when applying a first-class opcode to the wrong # of arguments --- eval.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/eval.c b/eval.c index 87e76051..1555ede2 100644 --- a/eval.c +++ b/eval.c @@ -1141,8 +1141,13 @@ static sexp make_param_list (sexp ctx, sexp_uint_t i) { static sexp make_opcode_procedure (sexp ctx, sexp op, sexp_uint_t i) { sexp ls, bc, res, env; sexp_gc_var5(params, ref, refs, lambda, ctx2); - if (i == sexp_opcode_num_args(op) && sexp_opcode_proc(op)) - return sexp_opcode_proc(op); /* return before preserving */ + if (i == sexp_opcode_num_args(op)) { /* return before preserving */ + if (sexp_opcode_proc(op)) return sexp_opcode_proc(op); + } else if (i < sexp_opcode_num_args(op)) { + return sexp_compile_error(ctx, "not enough args for opcode", op); + } else if (! sexp_opcode_variadic_p(op)) { /* i > num_args */ + return sexp_compile_error(ctx, "too many args for opcode", op); + } sexp_gc_preserve5(ctx, params, ref, refs, lambda, ctx2); params = make_param_list(ctx, i); lambda = sexp_make_lambda(ctx, params);