[bugfix] pic_get_args should ignore optional args when i > argc

This commit is contained in:
Yuichi Nishiwaki 2013-10-22 17:23:21 +09:00
parent b45d7d9592
commit d696339577
1 changed files with 19 additions and 8 deletions

View File

@ -27,6 +27,11 @@ pic_get_args(pic_state *pic, const char *format, ...)
case '|': case '|':
break; break;
} }
/* in order to run out of all arguments passed to this function
(i.e. do va_arg for each argument), optional argument existence
check is done in every case closure */
switch (c) { switch (c) {
case '|': case '|':
opt = true; opt = true;
@ -36,8 +41,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
pic_value *p; pic_value *p;
p = va_arg(ap, pic_value*); p = va_arg(ap, pic_value*);
*p = GET_OPERAND(pic,i); if (i < argc) {
i++; *p = GET_OPERAND(pic,i);
i++;
}
} }
break; break;
case 'f': case 'f':
@ -45,8 +52,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
double *f; double *f;
f = va_arg(ap, double *); f = va_arg(ap, double *);
*f = pic_float(GET_OPERAND(pic,i)); if (i < argc) {
i++; *f = pic_float(GET_OPERAND(pic,i));
i++;
}
} }
break; break;
case 's': case 's':
@ -57,10 +66,12 @@ pic_get_args(pic_state *pic, const char *format, ...)
cstr = va_arg(ap, char **); cstr = va_arg(ap, char **);
len = va_arg(ap, size_t *); len = va_arg(ap, size_t *);
str = GET_OPERAND(pic,i); if (i < argc) {
*cstr = pic_str_ptr(str)->str; str = GET_OPERAND(pic,i);
*len = pic_str_ptr(str)->len; *cstr = pic_str_ptr(str)->str;
i++; *len = pic_str_ptr(str)->len;
i++;
}
} }
break; break;
} }