From d63ab7046644df15664de777d3302d633bbe6b10 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 31 Aug 2022 19:06:41 +0900 Subject: [PATCH] Fix dangling pointer to VM value stack in krk_processComplexArguments Fixes #30 --- src/vm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/vm.c b/src/vm.c index 22385c8..9141338 100644 --- a/src/vm.c +++ b/src/vm.c @@ -428,11 +428,11 @@ int krk_processComplexArguments(int argCount, KrkValueArray * positionals, KrkTa krk_writeValueArray(positionals, krk_currentThread.stackTop[-argCount + i - TOP_ARGS]); } - KrkValue * startOfExtras = &krk_currentThread.stackTop[-kwargsCount * 2 - TOP_ARGS]; + size_t startOfExtras = &krk_currentThread.stackTop[-kwargsCount * 2 - TOP_ARGS] - krk_currentThread.stack; /* Now unpack everything else. */ for (size_t i = 0; i < kwargsCount; ++i) { - KrkValue key = startOfExtras[i*2]; - KrkValue value = startOfExtras[i*2 + 1]; + KrkValue key = krk_currentThread.stack[startOfExtras + i*2]; + KrkValue value = krk_currentThread.stack[startOfExtras + i*2 + 1]; if (IS_KWARGS(key)) { if (AS_INTEGER(key) == KWARGS_LIST) { /* unpack list */ if (krk_unpackIterable(value,positionals,_unpack_args)) return 0;