GothicKit / ZenKit

A re-implementation of file formats used by the early 2000's ZenGin

Home Page:http://zk.gothickit.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential Bug: Stack is cleared after Daedalus function call

lmichaelis opened this issue · comments

There might be a problem with this code, if a Daedalus function is called from within an external, because the entire stack (including previous function's stacks) might be cleared:

unsafe_call(sym);
if constexpr (std::is_same_v<R, IgnoreReturnValue>) {
// clear the stack
_m_stack_ptr = 0;
return {};
} else if constexpr (!std::is_same_v<R, void>) {
auto ret = pop_call_return_value<R>();
// clear the stack
_m_stack_ptr = 0;
return ret;
} else {
// clear the stack
_m_stack_ptr = 0;
}

Instead, we should clear the stack up to the previous call frame (taking into account return values). There should also be an unsafe function to trigger this behaviour from C and wrappers.

Fixed in f53a955 by properly counting stack size.