summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-06-07 18:26:49 +0200
committerJo-Philipp Wich <jo@mein.io>2021-06-07 18:26:49 +0200
commit856a0c05fbbde4363634e7f8d5de7ed66d0e0cdc (patch)
tree40ae5b043c3a0aa6d27f482f869f43da0202e919
parent86fb1300a500f6f49f1c6bb4f68c111106c862a5 (diff)
lib: only consider context of calling function for callbacks
Do not walk up the entire call stack but specifically use the context of the callframe calling the C function. Fixes: 3e893e6 ("lib: pass-through "this" context to library function callbacks") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/lib.c b/lib.c
index c9ebcb2..e95edd8 100644
--- a/lib.c
+++ b/lib.c
@@ -266,14 +266,9 @@ static void
uc_vm_ctx_push(uc_vm *vm)
{
uc_value_t *ctx = NULL;
- size_t i;
- for (i = vm->callframes.count; i > 0; i--) {
- if (vm->callframes.entries[i - 1].ctx) {
- ctx = vm->callframes.entries[i - 1].ctx;
- break;
- }
- }
+ if (vm->callframes.count >= 2)
+ ctx = vm->callframes.entries[vm->callframes.count - 2].ctx;
uc_vm_stack_push(vm, ucv_get(ctx));
}