fix some more edge cases
This commit is contained in:
19
pike.c
19
pike.c
@@ -437,7 +437,7 @@ int re_comp(rcode *prog, const char *re, int nsubs)
|
|||||||
if (freesub) \
|
if (freesub) \
|
||||||
{ s1 = freesub; freesub = (rsub*)s1->sub[0]; copy } \
|
{ s1 = freesub; freesub = (rsub*)s1->sub[0]; copy } \
|
||||||
else \
|
else \
|
||||||
{ s1 = (rsub*)&nsubs[rsubsize * subidx++]; init } \
|
{ s1 = (rsub*)&nsubs[suboff+=rsubsize]; init } \
|
||||||
|
|
||||||
#define decref(csub) \
|
#define decref(csub) \
|
||||||
if (--csub->ref == 0) { \
|
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 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 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;
|
const char *sp = s, *_sp = s;
|
||||||
int *insts = prog->insts;
|
int *insts = prog->insts;
|
||||||
int *pcs[prog->splits];
|
int *pcs[prog->splits];
|
||||||
rsub *subs[prog->splits];
|
rsub *subs[prog->splits];
|
||||||
char nsubs[rsubsize * 512];
|
char nsubs[500000];
|
||||||
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
rsub *nsub, *s1, *matched = NULL, *freesub = NULL;
|
||||||
rthread _clist[prog->len], _nlist[prog->len];
|
rthread _clist[prog->len], _nlist[prog->len];
|
||||||
rthread *clist = _clist, *nlist = _nlist, *tmp;
|
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:
|
case MATCH:
|
||||||
if (matched) {
|
if (matched) {
|
||||||
decref(matched)
|
decref(matched)
|
||||||
subidx = 0;
|
suboff = 0;
|
||||||
}
|
}
|
||||||
matched = nsub;
|
matched = nsub;
|
||||||
goto break_for;
|
goto break_for;
|
||||||
@@ -586,19 +586,16 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
|
|||||||
nlist = tmp;
|
nlist = tmp;
|
||||||
clistidx = nlistidx;
|
clistidx = nlistidx;
|
||||||
nlistidx = 0;
|
nlistidx = 0;
|
||||||
if (clistidx != 1 && !matched) {
|
if (!matched) {
|
||||||
if (!clistidx && pclistidx)
|
|
||||||
_sp = sp;
|
|
||||||
jmp_start:
|
jmp_start:
|
||||||
pclistidx = nlistidx;
|
|
||||||
newsub(for (i = 1; i < nsubp; i++) s1->sub[i] = NULL;, /*nop*/)
|
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;
|
||||||
npc = insts; nsub = s1;
|
nsub = s1;
|
||||||
|
npc = insts;
|
||||||
addthread(1, clist, clistidx)
|
addthread(1, clist, clistidx)
|
||||||
} else if (!clistidx)
|
} else if (!clistidx)
|
||||||
break;
|
break;
|
||||||
pclistidx = clistidx;
|
|
||||||
}
|
}
|
||||||
if (matched) {
|
if (matched) {
|
||||||
for (i = 0, j = i; i < nsubp; i+=2, j++) {
|
for (i = 0, j = i; i < nsubp; i+=2, j++) {
|
||||||
|
|||||||
18
test.sh
18
test.sh
@@ -115,6 +115,12 @@ qwerty.*$
|
|||||||
a(?:b|c|d){4,5}(.)
|
a(?:b|c|d){4,5}(.)
|
||||||
(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))
|
(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))
|
||||||
\\\\<abc
|
\\\\<abc
|
||||||
|
a\\\\([COM]+\\\\)|([A-Za-z_%.]+):
|
||||||
|
xyz\\\\([COM]+\\\\)|(abcd[A-Za-z_%.]+):cd
|
||||||
|
aaaaa(aa)aa(aa(a)a)?aa
|
||||||
|
^\\\\.+(((/)\\\\.\\\\.+)+)?
|
||||||
|
^(http|https|ftp):[/]{2}([a-zA-Z0-9\\\\\\\\.]+\\\\.[a-zA-Z]{2,4})(:[0-9]+)?/?([a-zA-Z0-9\\\\\\\\._?,'/+&%$#=~]*)
|
||||||
|
(\\\\$\\\\([a-zA-Z0-9_]+\\\\))|(([A-Za-z_%.]+):)
|
||||||
"
|
"
|
||||||
input="\
|
input="\
|
||||||
abcdef
|
abcdef
|
||||||
@@ -231,6 +237,12 @@ abcd
|
|||||||
acdbcdbe
|
acdbcdbe
|
||||||
cabbbb
|
cabbbb
|
||||||
dabc
|
dabc
|
||||||
|
a(COM:=.o):
|
||||||
|
xyz(abcdCOM:cd):
|
||||||
|
aaaaaaaaaaaaaaaaaaaaaaaaa
|
||||||
|
../../..
|
||||||
|
https://kyryl.tk/404
|
||||||
|
OBJ = \$(SRC:.c=.o)
|
||||||
"
|
"
|
||||||
expect="\
|
expect="\
|
||||||
(0,3)
|
(0,3)
|
||||||
@@ -347,6 +359,12 @@ expect="\
|
|||||||
(0,7)(6,7)
|
(0,7)(6,7)
|
||||||
(0,6)
|
(0,6)
|
||||||
-nomatch-
|
-nomatch-
|
||||||
|
(2,6)(2,5)
|
||||||
|
(4,14)(4,11)
|
||||||
|
(0,15)(5,7)(9,13)(11,12)
|
||||||
|
(0,8)(2,8)(5,8)(5,6)
|
||||||
|
(0,20)(0,5)(8,16)(?,?)(17,20)
|
||||||
|
(8,12)(?,?)(8,12)(8,11)
|
||||||
(0,0)
|
(0,0)
|
||||||
"
|
"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user