fix pathological cases
This commit is contained in:
13
pike.c
13
pike.c
@@ -427,10 +427,10 @@ int re_comp(rcode *prog, const char *re, int nsubs)
|
|||||||
#define _return(state) \
|
#define _return(state) \
|
||||||
{ prog->gen = gen + 1; return state; } \
|
{ prog->gen = gen + 1; return state; } \
|
||||||
|
|
||||||
#define newsub(init) \
|
#define newsub(init, copy) \
|
||||||
s1 = freesub; \
|
s1 = freesub; \
|
||||||
if (s1) \
|
if (s1) \
|
||||||
freesub = (rsub*)s1->sub[0]; \
|
{ freesub = (rsub*)s1->sub[0]; copy } \
|
||||||
else \
|
else \
|
||||||
{ s1 = (rsub*)&nsubs[rsubsize * subidx++]; init } \
|
{ s1 = (rsub*)&nsubs[rsubsize * subidx++]; init } \
|
||||||
|
|
||||||
@@ -454,12 +454,11 @@ subs[i++] = sub; \
|
|||||||
goto next##nn; \
|
goto next##nn; \
|
||||||
|
|
||||||
#define save1() \
|
#define save1() \
|
||||||
newsub(for (j = nsubp / 2; j < nsubp; j++) s1->sub[j] = NULL;) \
|
newsub(for (j = 0; j < nsubp; j++) s1->sub[j] = sub->sub[j];, \
|
||||||
for (j = 0; j < nsubp / 2; j++) \
|
for (j = 0; j < nsubp / 2; j++) s1->sub[j] = sub->sub[j];) \
|
||||||
s1->sub[j] = sub->sub[j]; \
|
|
||||||
|
|
||||||
#define save2() \
|
#define save2() \
|
||||||
newsub(/*nop*/) \
|
newsub(/*nop*/, /*nop*/) \
|
||||||
for (j = 0; j < nsubp; j++) \
|
for (j = 0; j < nsubp; j++) \
|
||||||
s1->sub[j] = sub->sub[j]; \
|
s1->sub[j] = sub->sub[j]; \
|
||||||
|
|
||||||
@@ -586,7 +585,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
nlistidx = 0;
|
nlistidx = 0;
|
||||||
if (!matched) {
|
if (!matched) {
|
||||||
jmp_start:
|
jmp_start:
|
||||||
newsub(for (i = 1; i < nsubp; i++) s1->sub[i] = NULL;)
|
newsub(for (i = 1; i < nsubp; i++) s1->sub[i] = NULL;, /*nop*/)
|
||||||
s1->ref = 1;
|
s1->ref = 1;
|
||||||
s1->sub[0] = _sp;
|
s1->sub[0] = _sp;
|
||||||
addthread(1, clist, clistidx, insts, s1)
|
addthread(1, clist, clistidx, insts, s1)
|
||||||
|
|||||||
24
test.sh
24
test.sh
@@ -106,6 +106,14 @@ qwerty.*$
|
|||||||
(aaaa|aaa|a){3,4}
|
(aaaa|aaa|a){3,4}
|
||||||
(a)(a)
|
(a)(a)
|
||||||
(a){2}
|
(a){2}
|
||||||
|
(a|bcdef|g|ab|c|d|e|efg|fg)*
|
||||||
|
(.*) (.*) (.*) (.*) (.*)
|
||||||
|
(.+?)(.+?)
|
||||||
|
(a?)(a?)(a?)aaa
|
||||||
|
(ab)?(ab)?(ab)?aaa
|
||||||
|
(.+)(.+)
|
||||||
|
a(?:b|c|d){4,5}(.)
|
||||||
|
(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))
|
||||||
"
|
"
|
||||||
input="\
|
input="\
|
||||||
abcdef
|
abcdef
|
||||||
@@ -213,6 +221,14 @@ aaaaaa
|
|||||||
aaaaaaaaaa
|
aaaaaaaaaa
|
||||||
aaaa
|
aaaa
|
||||||
aaaa
|
aaaa
|
||||||
|
abcdefg
|
||||||
|
a c d ee fff
|
||||||
|
abcd
|
||||||
|
aaa
|
||||||
|
abaaa
|
||||||
|
abcd
|
||||||
|
acdbcdbe
|
||||||
|
cabbbb
|
||||||
"
|
"
|
||||||
expect="\
|
expect="\
|
||||||
(0,3)
|
(0,3)
|
||||||
@@ -320,6 +336,14 @@ expect="\
|
|||||||
(0,10)(9,10)
|
(0,10)(9,10)
|
||||||
(0,2)(0,1)(1,2)
|
(0,2)(0,1)(1,2)
|
||||||
(0,2)(1,2)
|
(0,2)(1,2)
|
||||||
|
(0,7)(6,7)
|
||||||
|
(0,13)(0,2)(3,4)(5,6)(7,9)(10,13)
|
||||||
|
(0,2)(0,1)(1,2)
|
||||||
|
(0,3)(0,0)(0,0)(0,0)
|
||||||
|
(0,5)(0,2)(?,?)(?,?)
|
||||||
|
(0,4)(0,3)(3,4)
|
||||||
|
(0,7)(6,7)
|
||||||
|
(0,6)
|
||||||
(0,0)
|
(0,0)
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user