]> git.ipfire.org Git - thirdparty/git.git/blobdiff - wildmatch.c
wildmatch: avoid undefined behavior
[thirdparty/git.git] / wildmatch.c
index 06861bd8bc319cb57601965a255a21acd667aa4d..694d2f8e405287c154ff6e89911b8545f15e306d 100644 (file)
@@ -83,12 +83,12 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
                        continue;
                case '*':
                        if (*++p == '*') {
-                               const uchar *prev_p = p - 2;
+                               const uchar *prev_p = p;
                                while (*++p == '*') {}
                                if (!(flags & WM_PATHNAME))
                                        /* without WM_PATHNAME, '*' == '**' */
                                        match_slash = 1;
-                               else if ((prev_p < pattern || *prev_p == '/') &&
+                               else if ((prev_p - pattern < 2 || *(prev_p - 2) == '/') &&
                                    (*p == '\0' || *p == '/' ||
                                     (p[0] == '\\' && p[1] == '/'))) {
                                        /*