]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - posix/fnmatch_loop.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / posix / fnmatch_loop.c
index db6d9d7c56be3510dc391d44eacb5d3d9ffe9766..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
@@ -383,7 +379,7 @@ FCT (pattern, string, string_end, no_leading_period, flags, ends, alloca_used)
 # endif
                        const int32_t *indirect;
                        int32_t idx;
-                       const UCHAR *cp = (const UCHAR *) str;
+                       const UCHAR *cp = (const UCHAR *) &str;
 
 # if WIDE_CHAR_VERSION
                        table = (const int32_t *)
@@ -940,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;
@@ -1002,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;
@@ -1032,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;
 
@@ -1041,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)
 {