Skip to content

Commit

Permalink
Merge pull request #2095 from AlecTroemel/janet-buffer-hotfix
Browse files Browse the repository at this point in the history
make errBuffer pointer, avoid memory bug by not using janet_buffer_init
  • Loading branch information
nesbox authored Jan 25, 2023
2 parents eb4e331 + 36717da commit 60f2840
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/api/janet.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static const char* const JanetKeywords[] =
};

static JanetFiber* GameFiber = NULL;
static JanetBuffer errBuffer;
static JanetBuffer *errBuffer;
static tic_core* CurrentMachine = NULL;


Expand Down Expand Up @@ -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);
}


Expand All @@ -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;
}
}
Expand All @@ -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;
Expand Down

0 comments on commit 60f2840

Please sign in to comment.