Skip to content

Commit

Permalink
lj_state.c: Fix bug in allocation of IR buffer
Browse files Browse the repository at this point in the history
The pointer J->irbuf should point to the beginning of the allocated
memory, but was incorrectly offset by REF_BIAS.
  • Loading branch information
lukego committed Nov 29, 2017
1 parent 783cf2d commit bc57ceb
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/lj_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
J->sizesnapmap = sizeof(SnapEntry)*65536;
J->snapbuf = (SnapShot *)lj_mem_new(L, J->sizesnap);
J->snapmapbuf = (SnapEntry *)lj_mem_new(L, J->sizesnapmap);
IRIns *irbufmem = (IRIns *)lj_mem_new(L, sizeof(IRIns)*65536);
if (irbufmem == NULL || J->snapbuf == NULL || J->snapmapbuf == NULL)
J->irbuf = (IRIns *)lj_mem_new(L, sizeof(IRIns)*65536);
if (J->irbuf == NULL || J->snapbuf == NULL || J->snapmapbuf == NULL)
return NULL;
J->irbuf = irbufmem + REF_BIAS;
lj_dispatch_init((GG_State *)L);
L->status = LUA_ERRERR+1; /* Avoid touching the stack upon memory error. */
if (lj_vm_cpcall(L, NULL, NULL, cpluaopen) != 0) {
Expand Down

0 comments on commit bc57ceb

Please sign in to comment.