Commit fd5aec13 authored by Jamie A. Jennings's avatar Jamie A. Jennings

Loading and using patterns in rpl_1_2 engine causing a memory corruption!

parent 5dfb848d
......@@ -166,6 +166,9 @@ static void finalfix (lua_State *L, int postable, TTree *g, TTree *t, Ktable *kt
case TSeq: case TChoice:
correctassociativity(t);
break;
case TNoTree:
luaL_error(L, "cannot compile expression containing a precompiled pattern");
break;
}
switch (numsiblings[t->tag]) {
case 1: /* finalfix(L, postable, g, sib1(t)); */
......@@ -860,8 +863,9 @@ static Instruction *prepcompile (lua_State *L, Pattern *p);
static int r_codegen_if_needed (lua_State *L) {
Pattern *p = getpattern(L, 1);
if (p->code == NULL) /* not compiled yet? */
prepcompile(L, p);
lua_pushinteger(L, p->codesize);
if (!prepcompile(L, p)) lua_pushinteger(L, p->codesize);
else lua_pushnil(L);
else lua_pushinteger(L, p->codesize);
return 1;
}
......@@ -1236,6 +1240,10 @@ static void update_capture_keys(TTree *tree, int *mapping, int keymax) {
assert(rule->tag == TTrue); /* sentinel */
break;
}
case TNoTree: {
//luaL_error(L, "cannot compile expression containing a precompiled pattern");
break;
}
default: {
int sibs = numsiblings[tree->tag];
if (sibs >= 1) {
......@@ -1280,7 +1288,8 @@ static Instruction *prepcompile (lua_State *L, Pattern *p) {
compact_ktable(L, p); /* Remove duplicates in ktable, fixing up tree as needed */
Instruction *code = compile(L, p);
if (!code)
luaL_error(L, "cannot compile expression containing a precompiled pattern");
/* Other errors will be caught in finalfix() */
luaL_error(L, "internal error in rpeg compiler");
return code;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment