Fix returning strings from variadic functions.

This commit is contained in:
David Anderson
2014-08-17 10:00:51 -07:00
parent 63774d75f3
commit 6bbc4c8dbd
3 changed files with 78 additions and 3 deletions

View File

@ -5230,6 +5230,18 @@ static symbol *fetchlab(char *name)
return sym;
}
static int is_variadic(symbol *sym)
{
assert(sym->ident==iFUNCTN);
arginfo *arg = sym->dim.arglist;
while (arg->ident) {
if (arg->ident == iVARARGS)
return TRUE;
arg++;
}
return FALSE;
}
/* doreturn
*
* Global references: rettype (altered)
@ -5329,7 +5341,11 @@ static void doreturn(void)
* it stays on the heap for the moment, and it is removed -usually- at
* the end of the expression/statement, see expression() in SC3.C)
*/
address(sub,sALT); /* ALT = destination */
if (is_variadic(curfunc)) {
load_hidden_arg();
} else {
address(sub,sALT); /* ALT = destination */
}
arraysize=calc_arraysize(dim,numdim,0);
memcopy(arraysize*sizeof(cell)); /* source already in PRI */
/* moveto1(); is not necessary, callfunction() does a popreg() */