From b2c1f73e016f8f46a7534eb5f6456e9ec636fb4b Mon Sep 17 00:00:00 2001 From: CPunch Date: Wed, 16 Dec 2020 03:58:56 -0600 Subject: [PATCH] moved the results cap check in callCFunction --- src/cvm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cvm.c b/src/cvm.c index fcd12bb..40fb482 100644 --- a/src/cvm.c +++ b/src/cvm.c @@ -117,14 +117,14 @@ static inline void callCFunction(CState *state, CosmoCFunction cfunc, int args, int nres = cfunc(state, args, savedBase + 1); cosmoM_unfreezeGC(state); - // remember where the return values are + if (nres > nresults) // caller function wasn't expecting this many return values, cap it + nres = nresults; + + // remember where the return values are CValue* results = cosmoV_getTop(state, nres-1); state->top = savedBase + offset; // set stack - if (nres > nresults) // caller function wasn't expecting this many return values, cap it - nres = nresults; - // push the return value back onto the stack memcpy(state->top, results, sizeof(CValue) * nres); // copies the return values to the top of the stack state->top += nres; // and make sure to move state->top to match