]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - posix/fnmatch_loop.c
Increase some test timeouts.
[thirdparty/glibc.git] / posix / fnmatch_loop.c
index 1957397d24110e475974497cac82d59edeb9b6b2..e298cac5dcdc3209d2f4b6b741c99a251f1b8a1a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2014 Free Software Foundation, Inc.
+/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -28,24 +28,15 @@ struct STRUCT
    it matches, nonzero if not.  */
 static int FCT (const CHAR *pattern, const CHAR *string,
                const CHAR *string_end, int no_leading_period, int flags,
-               struct STRUCT *ends, size_t alloca_used)
-     internal_function;
+               struct STRUCT *ends, size_t alloca_used);
 static int EXT (INT opt, const CHAR *pattern, const CHAR *string,
                const CHAR *string_end, int no_leading_period, int flags,
-               size_t alloca_used)
-     internal_function;
-static const CHAR *END (const CHAR *patternp) internal_function;
+               size_t alloca_used);
+static const CHAR *END (const CHAR *patternp);
 
 static int
-internal_function
-FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
-     const CHAR *pattern;
-     const CHAR *string;
-     const CHAR *string_end;
-     int no_leading_period;
-     int flags;
-     struct STRUCT *ends;
-     size_t alloca_used;
+FCT (const CHAR *pattern, const CHAR *string, const CHAR *string_end,
+     int no_leading_period, int flags, struct STRUCT *ends, size_t alloca_used)
 {
   const CHAR *p = pattern, *n = string;
   UCHAR c;
@@ -343,7 +334,12 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 #ifdef _LIBC
                else if (c == L('[') && *p == L('='))
                  {
-                   UCHAR str[1];
+                   /* It's important that STR be a scalar variable rather
+                      than a one-element array, because GCC (at least 4.9.2
+                      -O2 on x86-64) can be confused by the array and
+                      diagnose a "used initialized" in a dead branch in the
+                      findidx function.  */
+                   UCHAR str;
                    uint32_t nrules =
                      _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_NRULES);
                    const CHAR *startp = p;
@@ -355,7 +351,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
                        c = L('[');
                        goto normal_bracket;
                      }
-                   str[0] = c;
+                   str = c;
 
                    c = *++p;
                    if (c != L('=') || p[1] != L(']'))
@@ -368,7 +364,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 
                    if (nrules == 0)
                      {
-                       if ((UCHAR) *n == str[0])
+                       if ((UCHAR) *n == str)
                          goto matched;
                      }
                    else
@@ -376,28 +372,21 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
                        const int32_t *table;
 # if WIDE_CHAR_VERSION
                        const int32_t *weights;
-                       const int32_t *extra;
+                       const wint_t *extra;
 # else
                        const unsigned char *weights;
                        const unsigned char *extra;
 # endif
                        const int32_t *indirect;
                        int32_t idx;
-                       const UCHAR *cp = (const UCHAR *) str;
-
-                       /* This #include defines a local function!  */
-# if WIDE_CHAR_VERSION
-#  include <locale/weightwc.h>
-# else
-#  include <locale/weight.h>
-# endif
+                       const UCHAR *cp = (const UCHAR *) &str;
 
 # if WIDE_CHAR_VERSION
                        table = (const int32_t *)
                          _NL_CURRENT (LC_COLLATE, _NL_COLLATE_TABLEWC);
                        weights = (const int32_t *)
                          _NL_CURRENT (LC_COLLATE, _NL_COLLATE_WEIGHTWC);
-                       extra = (const int32_t *)
+                       extra = (const wint_t *)
                          _NL_CURRENT (LC_COLLATE, _NL_COLLATE_EXTRAWC);
                        indirect = (const int32_t *)
                          _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTWC);
@@ -412,7 +401,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
                          _NL_CURRENT (LC_COLLATE, _NL_COLLATE_INDIRECTMB);
 # endif
 
-                       idx = findidx (&cp, 1);
+                       idx = FINDIDX (table, indirect, extra, &cp, 1);
                        if (idx != 0)
                          {
                            /* We found a table entry.  Now see whether the
@@ -422,7 +411,8 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
                            int32_t idx2;
                            const UCHAR *np = (const UCHAR *) n;
 
-                           idx2 = findidx (&np, string_end - n);
+                           idx2 = FINDIDX (table, indirect, extra,
+                                           &np, string_end - n);
                            if (idx2 != 0
                                && (idx >> 24) == (idx2 >> 24)
                                && len == weights[idx2 & 0xffffff])
@@ -946,14 +936,13 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
                  }
                else if (c == L('[') && *p == L('.'))
                  {
-                   ++p;
                    while (1)
                      {
                        c = *++p;
-                       if (c == '\0')
+                       if (c == L('\0'))
                          return FNM_NOMATCH;
 
-                       if (*p == L('.') && p[1] == L(']'))
+                       if (c == L('.') && p[1] == L(']'))
                          break;
                      }
                    p += 2;
@@ -1008,7 +997,6 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 
 
 static const CHAR *
-internal_function
 END (const CHAR *pattern)
 {
   const CHAR *p = pattern;
@@ -1038,7 +1026,12 @@ END (const CHAR *pattern)
       }
     else if ((*p == L('?') || *p == L('*') || *p == L('+') || *p == L('@')
              || *p == L('!')) && p[1] == L('('))
-      p = END (p + 1);
+      {
+       p = END (p + 1);
+       if (*p == L('\0'))
+         /* This is an invalid pattern.  */
+         return pattern;
+      }
     else if (*p == L(')'))
       break;
 
@@ -1047,7 +1040,6 @@ END (const CHAR *pattern)
 
 
 static int
-internal_function
 EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
      int no_leading_period, int flags, size_t alloca_used)
 {
@@ -1277,3 +1269,4 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
 #undef L
 #undef BTOWC
 #undef WIDE_CHAR_VERSION
+#undef FINDIDX