X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/5bb920003e47827ac92fad082fc24f03d5edf3a3..5f238db203f4ba876cfa8949f87f3f93507c049f:/lib/wildmatch.c diff --git a/lib/wildmatch.c b/lib/wildmatch.c index 8f7a5236..980bc49f 100644 --- a/lib/wildmatch.c +++ b/lib/wildmatch.c @@ -22,7 +22,7 @@ #define CC_EQ(class, len, litmatch) ((len) == sizeof (litmatch)-1 \ && *(class) == *(litmatch) \ - && strncmp(class, litmatch, len) == 0) + && strncmp((char*)class, litmatch, len) == 0) #if defined STDC_HEADERS || !defined isascii # define ISASCII(c) 1 @@ -57,10 +57,10 @@ int wildmatch_iteration_count; #endif -static int domatch(const unsigned char *p, const unsigned char *text) +static int domatch(const uchar *p, const uchar *text) { int matched, special; - unsigned char ch, prev; + uchar ch, prev; #ifdef WILD_TEST_ITERATIONS wildmatch_iteration_count++; @@ -94,7 +94,7 @@ static int domatch(const unsigned char *p, const unsigned char *text) if (*p == '\0') { /* Trailing "**" matches everything. Trailing "*" matches * only if there are no more slash characters. */ - return special? TRUE : strchr(text, '/') == NULL; + return special? TRUE : strchr((char*)text, '/') == NULL; } for ( ; *text; text++) { if ((matched = domatch(p, text)) != FALSE) { @@ -141,12 +141,20 @@ static int domatch(const unsigned char *p, const unsigned char *text) ch = 0; /* This makes "prev" get set to 0. */ } else if (ch == '[' && p[1] == ':') { - unsigned const char *s = p += 2; + const uchar *s; int i; - while ((ch = *p) && (ch != ':' || p[1] != ']')) p++; + for (s = p += 2; (ch = *p) && ch != ']'; p++) {} if (!ch) return ABORT_ALL; - i = p - s; + i = p - s - 1; + if (i < 0 || p[-1] != ':') { + /* Didn't find ":]", so treat like a normal set. */ + p = s - 2; + ch = '['; + if (*text == ch) + matched = TRUE; + continue; + } if (CC_EQ(s,i, "alnum")) { if (ISALNUM(*text)) matched = TRUE; @@ -197,13 +205,12 @@ static int domatch(const unsigned char *p, const unsigned char *text) } else /* malformed [:class:] string */ return ABORT_ALL; - p++; ch = 0; /* This makes "prev" get set to 0. */ } else if (*text == ch) matched = TRUE; } while (prev = ch, (ch = *++p) != ']'); - if (matched == special) + if (matched == special || *text == '/') return FALSE; continue; } @@ -218,5 +225,5 @@ int wildmatch(const char *p, const char *t) #ifdef WILD_TEST_ITERATIONS wildmatch_iteration_count = 0; #endif - return domatch((const unsigned char*)p, (const unsigned char*)t) == TRUE; + return domatch((const uchar*)p, (const uchar*)t) == TRUE; }