Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

Solaris Fixes #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lptree.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>


#include "lua.h"
Expand Down Expand Up @@ -1147,9 +1148,10 @@ static size_t initposition (lua_State *L, size_t len) {
** Main match function
*/
static int lp_match (lua_State *L) {
Capture capture[INITCAPSIZE];
Capture *capture = calloc(INITCAPSIZE, sizeof(Capture));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sanity check in case of failure.

const char *r;
size_t l;
int rv;
Pattern *p = (getpatt(L, 1, NULL), getpattern(L, 1));
Instruction *code = (p->code != NULL) ? p->code : prepcompile(L, p, 1);
const char *s = luaL_checklstring(L, SUBJIDX, &l);
Expand All @@ -1163,7 +1165,9 @@ static int lp_match (lua_State *L) {
lua_pushnil(L);
return 1;
}
return getcaptures(L, s, r, ptop);
rv = getcaptures(L, s, r, ptop);
free(capture);
return rv;
}


Expand Down
7 changes: 5 additions & 2 deletions lpvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <limits.h>
#include <string.h>
#include <stdlib.h>


#include "lua.h"
Expand Down Expand Up @@ -146,7 +147,7 @@ static int removedyncap (lua_State *L, Capture *capture,
*/
const char *match (lua_State *L, const char *o, const char *s, const char *e,
Instruction *op, Capture *capture, int ptop) {
Stack stackbase[INITBACK];
Stack *stackbase = calloc(INITBACK, sizeof(Stack));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sanity check present in case of failure.

Stack *stacklimit = stackbase + INITBACK;
Stack *stack = stackbase; /* point to first empty slot in stack */
int capsize = INITCAPSIZE;
Expand All @@ -168,10 +169,12 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
assert(stack == getstackbase(L, ptop) + 1);
capture[captop].kind = Cclose;
capture[captop].s = NULL;
free(stackbase);
return s;
}
case IGiveup: {
assert(stack == getstackbase(L, ptop));
free(stackbase);
return NULL;
}
case IRet: {
Expand Down Expand Up @@ -345,7 +348,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e,
p++;
continue;
}
default: assert(0); return NULL;
default: assert(0); free(stackbase); return NULL;
}
}
}
Expand Down