From 33ab8be7e3a32182e1397e403d6ee8a5e8b342c8 Mon Sep 17 00:00:00 2001 From: Joram Vandemoortele Date: Sun, 4 Apr 2021 20:24:48 +0200 Subject: [PATCH] fix possibility of having no reallocate function (#954) Before, if a config was provided it was expected to have a reallocate function, now it can remain null and the default will be used. --- src/vm/wren_vm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index a63f973e..dd8a8b63 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -56,8 +56,8 @@ WrenVM* wrenNewVM(WrenConfiguration* config) WrenReallocateFn reallocate = defaultReallocate; void* userData = NULL; if (config != NULL) { - reallocate = config->reallocateFn; userData = config->userData; + reallocate = config->reallocateFn ? config->reallocateFn : defaultReallocate; } WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm), userData); @@ -67,6 +67,10 @@ WrenVM* wrenNewVM(WrenConfiguration* config) if (config != NULL) { memcpy(&vm->config, config, sizeof(WrenConfiguration)); + + // We choose to set this after copying, + // rather than modifying the user config pointer + vm->config.reallocateFn = reallocate; } else {