[gamecode] Use a buffer for discarded return values

Due to how OP_RETURN works, a destination is required for any function
returning data, but the caller may not have allocated any space for the
value. Thus the VM maintains a buffer into which the data can be put and
ignored. It also makes a good place for return values when the engine
calls Ruamoko code as trusting progs code with return sizes seems like a
recipe for disaster, especially if the return location is on the C
stack.
This commit is contained in:
Bill Currie 2022-01-21 10:09:02 +09:00
parent 4b87d24737
commit 578314c5a3
2 changed files with 5 additions and 0 deletions

View file

@ -1896,6 +1896,8 @@ struct progs_s {
pr_type_t *pr_real_params[MAX_PARMS];
int pr_param_size; ///< covers both params and return
int pr_param_alignment; ///< covers both params and return
pr_type_t pr_return_buffer[32];///< for discarded return values
///< or returning values to C
///@}
/// \name edicts

View file

@ -427,6 +427,9 @@ PR_CallFunction (progs_t *pr, pr_func_t fnum, pr_type_t *return_ptr)
if (!fnum)
PR_RunError (pr, "NULL function");
if (!return_ptr || return_ptr == pr->pr_globals) {
return_ptr = pr->pr_return_buffer;
}
f = pr->function_table + fnum;
if (f->first_statement < 0) {
// negative statements are built in functions