fix regressions on a[^b]*c cases

This commit is contained in:
Kyryl Melekhin
2021-08-07 16:20:46 +00:00
parent e71f2d2b46
commit e44e6a9517
2 changed files with 19 additions and 5 deletions

12
pike.c
View File

@@ -469,7 +469,6 @@ goto next##nn; \
#define addthread(nn, list, listidx, _pc, _sub) \ #define addthread(nn, list, listidx, _pc, _sub) \
{ \ { \
int i = 0, *pc = _pc; \ int i = 0, *pc = _pc; \
const char *_sp = sp+l; \
rsub *sub = _sub; \ rsub *sub = _sub; \
rec##nn: \ rec##nn: \
if (*pc < WBEG) { \ if (*pc < WBEG) { \
@@ -544,11 +543,11 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
int i, j, c, l = 0, gen, subidx = 1, *npc; int i, j, c, l = 0, gen, subidx = 1, *npc;
int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp); int rsubsize = sizeof(rsub)+(sizeof(char*)*nsubp);
int clistidx = 0, nlistidx = 0; int clistidx = 0, nlistidx = 0;
const char *sp = s; const char *sp = s, *_sp = s;
int *insts = prog->insts, *plist = insts+prog->unilen; int *insts = prog->insts, *plist = insts+prog->unilen;
int *pcs[prog->splits]; int *pcs[prog->splits];
rsub *subs[prog->splits]; rsub *subs[prog->splits];
char nsubs[rsubsize * (prog->len - prog->splits)]; char nsubs[rsubsize * (prog->len+3 - prog->splits)];
rsub *nsub = (rsub*)nsubs, *matched = NULL, *s1; rsub *nsub = (rsub*)nsubs, *matched = NULL, *s1;
rsub *freesub = NULL; rsub *freesub = NULL;
rthread _clist[prog->len]; rthread _clist[prog->len];
@@ -558,8 +557,9 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
subp[i] = NULL; subp[i] = NULL;
gen = prog->gen; gen = prog->gen;
goto jmp_start; goto jmp_start;
for(;; sp += l) { for(;; sp = _sp) {
gen++; uc_len(l, sp) uc_code(c, sp) gen++; uc_len(l, sp) uc_code(c, sp)
_sp = sp+l;
for(i = 0; i < clistidx; i++) { for(i = 0; i < clistidx; i++) {
npc = clist[i].pc; npc = clist[i].pc;
nsub = clist[i].sub; nsub = clist[i].sub;
@@ -576,6 +576,8 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
npc += *(npc+1) * 2 + 2; npc += *(npc+1) * 2 + 2;
goto addthread; goto addthread;
case MATCH: case MATCH:
if (matched)
decref(matched)
matched = nsub; matched = nsub;
subidx = 0; subidx = 0;
goto break_for; goto break_for;
@@ -596,7 +598,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
s1->ref = 1; s1->ref = 1;
for (i = 1; i < nsubp; i++) for (i = 1; i < nsubp; i++)
s1->sub[i] = NULL; s1->sub[i] = NULL;
s1->sub[0] = sp + l; s1->sub[0] = _sp;
addthread(1, clist, clistidx, insts, s1) addthread(1, clist, clistidx, insts, s1)
} else if (!clistidx) } else if (!clistidx)
break; break;

12
test.sh
View File

@@ -92,6 +92,10 @@ abc\\\\>
[-+]?\\\\<(0[xX][0-9a-fA-FUL]+|[0-9.]{1,}[0-9eEfFuULl]+|[0-9]+)\\\\> [-+]?\\\\<(0[xX][0-9a-fA-FUL]+|[0-9.]{1,}[0-9eEfFuULl]+|[0-9]+)\\\\>
[-+]?\\\\<(0[xX][0-9a-fA-FUL]+|[0-9.]{1,}[0-9eEfFuULl]+|[0-9]+)\\\\> [-+]?\\\\<(0[xX][0-9a-fA-FUL]+|[0-9.]{1,}[0-9eEfFuULl]+|[0-9]+)\\\\>
qwerty.*$ qwerty.*$
([a-zA-Z0-9_][^1]*[a-zA-Z0-9_])|(\\\\\$([^\$]+)\\\\\$)
([a-zA-Z0-9_][^1]*[a-zA-Z0-9_])|(\\\\\$([^\$]+)\\\\\$)
(h[^1]*b)|(\\\\\$([^\$]+)\\\\\$)
(h[^1]*b)|(\\\\\$([^\$]+)\\\\\$)
" "
input="\ input="\
abcdef abcdef
@@ -185,6 +189,10 @@ world
x37247 x37247
124435.7727ULL 124435.7727ULL
jjdfjk sjdjjsqwerty jdfjdfhhdhfdjjjfj jjjdf jjdfjk sjdjjsqwerty jdfjdfhhdhfdjjjfj jjjdf
$\"}, /* email */
$\"}, /* email */$
$ hbbbb
$ hsdhs $
" "
expect="\ expect="\
(0,3) (0,3)
@@ -278,6 +286,10 @@ expect="\
-nomatch- -nomatch-
(2,16)(2,16) (2,16)(2,16)
(14,44) (14,44)
(9,14)(9,14)(?,?)(?,?)
(0,18)(?,?)(0,18)(1,17)
(3,8)(3,8)(?,?)(?,?)
(0,9)(?,?)(0,9)(1,8)
(0,0) (0,0)
" "