fix a bug

This commit is contained in:
Sunrin SHIMURA (keen) 2015-02-03 17:19:17 +00:00
parent 1700610729
commit 65967f2e05
1 changed files with 10 additions and 13 deletions

View File

@ -58,8 +58,8 @@ int
pic_get_args(pic_state *pic, const char *format, ...) pic_get_args(pic_state *pic, const char *format, ...)
{ {
char c; char c;
int paramc, optc, min; size_t paramc, optc, min;
int i , argc = pic->ci->argc - 1; size_t i , argc = pic->ci->argc - 1;
va_list ap; va_list ap;
bool rest = false, opt = false; bool rest = false, opt = false;
@ -103,7 +103,7 @@ pic_get_args(pic_state *pic, const char *format, ...)
/* start dispatching */ /* start dispatching */
va_start(ap, format); 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++) { for(i = 1; i < min + 1; i++) {
c = *format++; c = *format++;
@ -382,22 +382,19 @@ pic_get_args(pic_state *pic, const char *format, ...)
} }
break; break;
} }
case '*': { default:
pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c);
}
}
if (rest) {
size_t *n; size_t *n;
pic_value **argv; pic_value **argv;
n = va_arg(ap, size_t *); n = va_arg(ap, size_t *);
argv = va_arg(ap, pic_value **); argv = va_arg(ap, pic_value **);
if ( paramc + optc < argc) { *n = (size_t)(argc - (i - 1));
*n = (size_t)(argc - (paramc + optc)); *argv = &GET_OPERAND(pic, i);
*argv = &GET_OPERAND(pic, i);
}
break;
} }
default:
pic_errorf(pic, "pic_get_args: invalid argument specifier '%c' given", c);
}
}
va_end(ap); va_end(ap);
return argc; return argc;
} }