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) \
|
||||
{ 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++) {
|
||||
|
||||
18
test.sh
18
test.sh
@@ -115,6 +115,12 @@ qwerty.*$
|
||||
a(?:b|c|d){4,5}(.)
|
||||
(?:c|d)(?:)(?:a(?:)(?:b)(?:b(?:))(?:b(?:)(?:b)))
|
||||
\\\\<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="\
|
||||
abcdef
|
||||
@@ -231,6 +237,12 @@ abcd
|
||||
acdbcdbe
|
||||
cabbbb
|
||||
dabc
|
||||
a(COM:=.o):
|
||||
xyz(abcdCOM:cd):
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
../../..
|
||||
https://kyryl.tk/404
|
||||
OBJ = \$(SRC:.c=.o)
|
||||
"
|
||||
expect="\
|
||||
(0,3)
|
||||
@@ -347,6 +359,12 @@ expect="\
|
||||
(0,7)(6,7)
|
||||
(0,6)
|
||||
-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)
|
||||
"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user