diff options
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/regex/engine.c | 30 | ||||
-rw-r--r-- | lib/libc/regex/regcomp.c | 8 |
2 files changed, 17 insertions, 21 deletions
diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c index 8bc3de8..a12538f 100644 --- a/lib/libc/regex/engine.c +++ b/lib/libc/regex/engine.c @@ -155,15 +155,12 @@ int eflags; char *start; char *stop; /* Boyer-Moore algorithms variables */ - register unsigned char *pp; + register char *pp; int cj, mj; - register unsigned char *mustfirst; - register unsigned char *mustlast; - register int mustlen; + register char *mustfirst; + register char *mustlast; register int *matchjump; register int *charjump; - register unsigned char *bmp; - register unsigned char *bmps; /* simplify the situation where possible */ if (g->cflags®_NOSUB) @@ -181,39 +178,36 @@ int eflags; /* prescreening; this does wonders for this rather slow code */ if (g->must != NULL) { if (g->charjump != NULL && g->matchjump != NULL) { - mustlen = -g->mlen; mustfirst = g->must; mustlast = g->must + g->mlen - 1; charjump = g->charjump; matchjump = g->matchjump; - bmps = stop; pp = mustlast; - for (bmp = start+g->mlen-1; bmp < bmps;) { + for (dp = start+g->mlen-1; dp < stop;) { /* Fast skip non-matches */ - while (bmp < bmps && charjump[*bmp]) - bmp += charjump[*bmp]; + while (dp < stop && charjump[*dp]) + dp += charjump[*dp]; - if (bmp >= bmps) + if (dp >= stop) break; /* Greedy matcher */ /* We depend on not being used for * for strings of length 1 */ - while (*--bmp == *--pp && pp != mustfirst); + while (*--dp == *--pp && pp != mustfirst); - if (*bmp == *pp) + if (*dp == *pp) break; /* Jump to next possible match */ mj = matchjump[pp - mustfirst]; - cj = charjump[*bmp]; - bmp += (cj < mj ? mj : cj); - pp = mustlast; + cj = charjump[*dp]; + dp += (cj < mj ? mj : cj); + pp = mustlast; } if (pp != mustfirst) return(REG_NOMATCH); - dp = bmp; } else { for (dp = start; dp < stop; dp++) if (*dp == g->must[0] && diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index e943374..9664084 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1942,14 +1942,16 @@ struct re_guts *g; if (p->error != 0) return; - g->charjump = malloc((UCHAR_MAX+1) * sizeof(int)); + g->charjump = malloc((NC + 1) * sizeof(int)); if (g->charjump == NULL) /* Not a fatal error */ return; + /* Adjust for signed chars, if necessary */ + g->charjump = &g->charjump[-(CHAR_MIN)]; /* If the character does not exist in the pattern, the jump * is equal to the number of characters in the pattern. */ - for (ch = 0; ch < (UCHAR_MAX+1); ch++) + for (ch = CHAR_MIN; ch < (CHAR_MAX + 1); ch++) g->charjump[ch] = g->mlen; /* If the character does exist, compute the jump that would @@ -1958,7 +1960,7 @@ struct re_guts *g; * is the first one that would be matched). */ for (mindex = 0; mindex < g->mlen; mindex++) - g->charjump[(unsigned char)g->must[mindex]] = g->mlen - mindex - 1; + g->charjump[g->must[mindex]] = g->mlen - mindex - 1; } /* |