From 65967f2e05236c7f4e4b8c7e611e0cc8de3ca0da Mon Sep 17 00:00:00 2001 From: "Sunrin SHIMURA (keen)" <3han5chou7@gmail.com> Date: Tue, 3 Feb 2015 17:19:17 +0000 Subject: [PATCH] fix a bug --- extlib/benz/vm.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/extlib/benz/vm.c b/extlib/benz/vm.c index a55489b1..20165127 100644 --- a/extlib/benz/vm.c +++ b/extlib/benz/vm.c @@ -58,8 +58,8 @@ int pic_get_args(pic_state *pic, const char *format, ...) { char c; - int paramc, optc, min; - int i , argc = pic->ci->argc - 1; + size_t paramc, optc, min; + size_t i , argc = pic->ci->argc - 1; va_list ap; bool rest = false, opt = false; @@ -103,7 +103,7 @@ pic_get_args(pic_state *pic, const char *format, ...) /* start dispatching */ va_start(ap, format); - min = paramc + optc + rest < argc ? paramc + optc + rest : argc; + min = paramc + optc < argc ? paramc + optc : argc; for(i = 1; i < min + 1; i++) { c = *format++; @@ -382,22 +382,19 @@ pic_get_args(pic_state *pic, const char *format, ...) } break; } - case '*': { + default: + pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c); + } + } + if (rest) { size_t *n; pic_value **argv; n = va_arg(ap, size_t *); argv = va_arg(ap, pic_value **); - if ( paramc + optc < argc) { - *n = (size_t)(argc - (paramc + optc)); - *argv = &GET_OPERAND(pic, i); - } - break; + *n = (size_t)(argc - (i - 1)); + *argv = &GET_OPERAND(pic, i); } - default: - pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c); - } - } va_end(ap); return argc; }