From 36717dae9890a54a227338686963de24e9ff7a34 Mon Sep 17 00:00:00 2001 From: alectroemel Date: Mon, 23 Jan 2023 20:45:41 -0600 Subject: [PATCH] make errBuffer pointer, avoid memory bug by not using janet_buffer_init --- src/api/janet.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/api/janet.c b/src/api/janet.c index 7b383839e..19ce35a2f 100644 --- a/src/api/janet.c +++ b/src/api/janet.c @@ -160,7 +160,7 @@ static const char* const JanetKeywords[] = }; static JanetFiber* GameFiber = NULL; -static JanetBuffer errBuffer; +static JanetBuffer *errBuffer; static tic_core* CurrentMachine = NULL; @@ -1011,8 +1011,8 @@ static Janet janet_fset(int32_t argc, Janet* argv) static void reportError(tic_core* core, Janet result) { janet_stacktrace(GameFiber, result); - janet_buffer_push_u8(&errBuffer, 0); - core->data->error(core->data->data, errBuffer.data); + janet_buffer_push_u8(errBuffer, 0); + core->data->error(core->data->data, errBuffer->data); } @@ -1024,7 +1024,7 @@ static void closeJanet(tic_mem* tic) janet_deinit(); core->currentVM = NULL; CurrentMachine = NULL; - janet_buffer_deinit(&errBuffer); + errBuffer = NULL; GameFiber = NULL; } } @@ -1047,8 +1047,8 @@ static bool initJanet(tic_mem* tic, const char* code) core->currentVM = (JanetTable*)janet_core_env(NULL); // override the dynamic err to a buffer, so that we can get errors later - janet_buffer_init(&errBuffer, 1028); - janet_setdyn("err", janet_wrap_buffer(&errBuffer)); + errBuffer = janet_buffer(1028); + janet_setdyn("err", janet_wrap_buffer(errBuffer)); GameFiber = janet_current_fiber(); Janet result;