fix some more edge cases

This commit is contained in:
Kyryl Melekhin
2021-09-22 10:31:28 +00:00
parent cc17c0bb05
commit e3bede1739
2 changed files with 26 additions and 11 deletions

19
pike.c
View File

@@ -437,7 +437,7 @@ int re_comp(rcode *prog, const char *re, int nsubs)
if (freesub) \
{ s1 = freesub; freesub = (rsub*)s1->sub[0]; copy } \
else \
{ s1 = (rsub*)&nsubs[rsubsize * subidx++]; init } \
{ s1 = (rsub*)&nsubs[suboff+=rsubsize]; init } \
#define decref(csub) \
if (--csub->ref == 0) { \
@@ -537,14 +537,14 @@ for (j = 0; j < nsubp; j++) s1->sub[j] = nsub->sub[j]; \
int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
{
int i, j, c, gen, subidx = 1, *npc;
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
int clistidx = 0, nlistidx = 0, pclistidx;
int i, j, c, gen, suboff = rsubsize, *npc;
int clistidx = 0, nlistidx = 0;
const char *sp = s, *_sp = s;
int *insts = prog->insts;
int *pcs[prog->splits];
rsub *subs[prog->splits];
char nsubs[rsubsize * 512];
char nsubs[500000];
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
rthread _clist[prog->len], _nlist[prog->len];
rthread *clist = _clist, *nlist = _nlist, *tmp;
@@ -571,7 +571,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
case MATCH:
if (matched) {
decref(matched)
subidx = 0;
suboff = 0;
}
matched = nsub;
goto break_for;
@@ -586,19 +586,16 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
nlist = tmp;
clistidx = nlistidx;
nlistidx = 0;
if (clistidx != 1 && !matched) {
if (!clistidx && pclistidx)
_sp = sp;
if (!matched) {
jmp_start:
pclistidx = nlistidx;
newsub(for (i = 1; i < nsubp; i++) s1->sub[i] = NULL;, /*nop*/)
s1->ref = 1;
s1->sub[0] = _sp;
npc = insts; nsub = s1;
nsub = s1;
npc = insts;
addthread(1, clist, clistidx)
} else if (!clistidx)
break;
pclistidx = clistidx;
}
if (matched) {
for (i = 0, j = i; i < nsubp; i+=2, j++) {