fix missing iteration

This commit is contained in:
Kyryl Melekhin
2022-04-16 18:17:54 +00:00
parent 26b5b25149
commit f0da1db9cc
2 changed files with 28 additions and 4 deletions

5
pike.c
View File

@@ -601,7 +601,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
}
matched = nsub;
}
if (sp == _sp || nlistidx == 1) {
if ((sp == _sp || nlistidx == 1) && matched->sub[nsubp/2]) {
for (i = 0, j = i; i < nsubp; i+=2, j++) {
subp[i] = matched->sub[j];
subp[i+1] = matched->sub[nsubp / 2 + j];
@@ -656,9 +656,6 @@ int main(int argc, char *argv[])
printf("Done in %f seconds\n", elapsed_time);
if (!sz)
{ printf("-nomatch-\n"); continue; }
for (int k = sub_els; k > 0; k--)
if (sub[k-1])
break;
for (int l = 0; l < sub_els; l+=2) {
printf("(");
if (sub[l] == NULL || sub[l+1] == NULL)

27
test.sh
View File

@@ -155,6 +155,15 @@ aaaaa(aa)aa(aa(a)a)?aa
\\\\\\\\<
\\\\\\\\\\\\\\\\<
[^a]*b
^(.+):([0-9]+):(.+)
^(.+):([0-9]+):(.+)
^(.+):([0-9]+):(.+)
^(.+):([0-9]+):(.+)(.+)
(.*):([0-9]*):(.*)
(.*):([0-9]*)( ):((.*)+)
(((aaa+)+)bb*)(.*):([0-9]*):(.+)
^(.+):([0-9]+):(.{8})+
^(.+):([0-9]+):((aaaa)|(.+))\"
"
input="\
abcdef
@@ -311,6 +320,15 @@ xabcx
\\<
\\\\\\\\<
hhagbdbdbjsjjjda..b
userspace-api/media/v4l/vbi_625.svg:98: :34bstroke-linejoin:m;stroke-miteit:10;stroke-day:n;se-ty:1\"
h:98: :3234434butt;stroke-linejoin:miter;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1\"
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
aaaaabb grt:123:....
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
h:98: :3234utt;strokeliin:miter;stroke-mirlimit:10;stroke-dasharray:none;stroke-opacity:1n\"
"
expect="\
(0,3)
@@ -467,6 +485,15 @@ expect="\
(0,2)
(2,5)
(3,9)
(0,102)(0,35)(36,38)(39,102)
(0,103)(0,1)(2,4)(5,103)
(0,93)(0,1)(2,4)(5,93)
(0,93)(0,1)(2,4)(5,92)(92,93)
(0,93)(0,1)(2,4)(5,93)
(0,93)(0,4)(5,5)(5,8)(9,93)(9,93)
(0,20)(0,7)(0,5)(0,5)(7,11)(12,15)(16,20)
(0,93)(0,1)(2,4)(85,93)
(0,93)(0,1)(2,4)(5,92)(?,?)(5,92)
(0,0)
"