pike.c: handle 0 case in repetition
This commit is contained in:
17
pike.c
17
pike.c
@@ -268,7 +268,7 @@ static int compilecode(const char *re_loc, rcode *prog, int sizecode)
|
||||
}
|
||||
break;
|
||||
case '{':;
|
||||
int maxcnt = 0, mincnt = 0, i = 0, size = PC - term;
|
||||
int i, maxcnt = 0, mincnt = 0, size = PC - term, nojmp = 0;
|
||||
re++;
|
||||
while (isdigit((unsigned char) *re))
|
||||
mincnt = mincnt * 10 + *re++ - '0';
|
||||
@@ -279,12 +279,21 @@ static int compilecode(const char *re_loc, rcode *prog, int sizecode)
|
||||
EMIT(PC+1, REL(PC, PC - size));
|
||||
PC += 2;
|
||||
maxcnt = mincnt;
|
||||
nojmp = 1;
|
||||
}
|
||||
while (isdigit((unsigned char) *re))
|
||||
maxcnt = maxcnt * 10 + *re++ - '0';
|
||||
} else
|
||||
maxcnt = mincnt;
|
||||
for (; i < mincnt-1; i++) {
|
||||
if (!mincnt && !maxcnt) {
|
||||
zcase:
|
||||
INSERT_CODE(term, 2, PC);
|
||||
EMIT(term, nojmp ? SPLIT : JMP);
|
||||
EMIT(term + 1, REL(term, PC));
|
||||
term = PC;
|
||||
break;
|
||||
}
|
||||
for (i = 0; i < mincnt-1; i++) {
|
||||
if (code)
|
||||
memcpy(&code[PC], &code[term], size*sizeof(int));
|
||||
PC += size;
|
||||
@@ -296,6 +305,10 @@ static int compilecode(const char *re_loc, rcode *prog, int sizecode)
|
||||
memcpy(&code[PC], &code[term], size*sizeof(int));
|
||||
PC += size;
|
||||
}
|
||||
if (!mincnt && maxcnt) {
|
||||
nojmp = 1;
|
||||
goto zcase;
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
if (PC == term)
|
||||
|
||||
Reference in New Issue
Block a user