fixed the fault in checking the number of arguments for variadic functions in hawk_rtx_evalcall()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ca5ca2c3ce
commit
b6a512f90f
22
lib/run.c
22
lib/run.c
@ -6011,7 +6011,7 @@ static hawk_val_t* eval_binop_mod (hawk_rtx_t* rtx, hawk_val_t* left, hawk_val_t
|
|||||||
switch (n3)
|
switch (n3)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
if (l2 == 0)
|
if (l2 == 0)
|
||||||
{
|
{
|
||||||
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0);
|
hawk_rtx_seterrnum (rtx, HAWK_NULL, HAWK_EDIVBY0);
|
||||||
return HAWK_NULL;
|
return HAWK_NULL;
|
||||||
@ -6793,9 +6793,11 @@ hawk_val_t* hawk_rtx_evalcall (
|
|||||||
|
|
||||||
/* make a new stack frame */
|
/* make a new stack frame */
|
||||||
stack_req = 4 + call->nargs;
|
stack_req = 4 + call->nargs;
|
||||||
if (fun)
|
if (fun && fun->nargs > call->nargs)
|
||||||
{
|
{
|
||||||
HAWK_ASSERT (fun->nargs >= call->nargs); /* the compiler must guarantee this */
|
/* for variadic functions, fun->nargs can be less than call->nargs.
|
||||||
|
* for non-variadic functions, the compiler must guarantee that fun->nargs >= call->nargs
|
||||||
|
* this case can happen for for non-variadic functions only. */
|
||||||
stack_req += fun->nargs - call->nargs;
|
stack_req += fun->nargs - call->nargs;
|
||||||
}
|
}
|
||||||
/* if fun is HAWK_NULL, there is no way for this function to know expected argument numbers.
|
/* if fun is HAWK_NULL, there is no way for this function to know expected argument numbers.
|
||||||
@ -7153,25 +7155,11 @@ static hawk_oow_t push_arg_from_nde (hawk_rtx_t* rtx, hawk_nde_fncall_t* call, v
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'V':
|
|
||||||
/* the variadic argument marked with ... in the function parameter */
|
|
||||||
if (p->type == HAWK_NDE_LCL)
|
|
||||||
{
|
|
||||||
hawk_nde_var_t* var = (hawk_nde_var_t*)p;
|
|
||||||
v = hawk_rtx_makeintval(rtx, ((hawk_nde_var_t*)p)->id.idxa);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* THIS IS THE RUNTIME ERROR */
|
|
||||||
/* TODO: */
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
/* a regular expression is passed to the function as it is */
|
/* a regular expression is passed to the function as it is */
|
||||||
v = eval_expression0(rtx, p);
|
v = eval_expression0(rtx, p);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
normal_arg:
|
normal_arg:
|
||||||
v = eval_expression(rtx, p);
|
v = eval_expression(rtx, p);
|
||||||
|
@ -585,7 +585,7 @@ function main()
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
@local a, b;
|
@local a, b, f;
|
||||||
|
|
||||||
RSTART=99;
|
RSTART=99;
|
||||||
RLENGTH=99;
|
RLENGTH=99;
|
||||||
@ -652,6 +652,12 @@ function main()
|
|||||||
tap_ensure (test10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (test10(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
tap_ensure (test11("aa", "bb", "cc"), 0, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (test11("aa", "bb", "cc"), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
tap_ensure (test11("aa", "bb", "cc", "dd"), 1, @SCRIPTNAME, @SCRIPTLINE);
|
tap_ensure (test11("aa", "bb", "cc", "dd"), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
|
f = test11;
|
||||||
|
tap_ensure (f("aa", "bb", "cc", "dd"), 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
|
|
||||||
|
f = test10
|
||||||
|
tap_ensure (f(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), 55, @SCRIPTNAME, @SCRIPTLINE);
|
||||||
}
|
}
|
||||||
tap_end ();
|
tap_end ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user