]> Savannah Git Hosting - gnulib.git/commitdiff
fnmatch: merge from glibc + proposal
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Dec 2020 21:35:53 +0000 (13:35 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 31 Dec 2020 21:43:59 +0000 (13:43 -0800)
This merges the change proposed by Adhemerval Zanella in:
https://sourceware.org/pipermail/libc-alpha/2020-December/121212.html
which fixes a Gnulib bug that led to a failed assert.
* lib/fnmatch_loop.c (EXT): Use signed level, not unsigned, and
check that it stays nonnegative.  Use __flexarr instead of
FLEXIBLE_ARRAY_MEMBER, to port better to glibc.
* tests/test-fnmatch.c (main): New test cases, taken from glibc.

ChangeLog
lib/fnmatch_loop.c
tests/test-fnmatch.c

index 5da7c043a860f76dd548eafa76fc9eb372b5aafd..661a1ee94d023f771d7f0b2a5737b91d775c8cd7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2020-12-31  Paul Eggert  <eggert@cs.ucla.edu>
 
+       fnmatch: merge from glibc + proposal
+       This merges the change proposed by Adhemerval Zanella in:
+       https://sourceware.org/pipermail/libc-alpha/2020-December/121212.html
+       which fixes a Gnulib bug that led to a failed assert.
+       * lib/fnmatch_loop.c (EXT): Use signed level, not unsigned, and
+       check that it stays nonnegative.  Use __flexarr instead of
+       FLEXIBLE_ARRAY_MEMBER, to port better to glibc.
+       * tests/test-fnmatch.c (main): New test cases, taken from glibc.
+
        glob: merge proposed glibc changes
        This merges the change proposed by Adhemerval Zanella in:
        https://sourceware.org/pipermail/libc-alpha/2020-December/121211.html
index c533107a2a7f5141c25a93efe2a745540b35b3fe..e5dac38b45d619dbce48fea9746fdea4bb7e4c3c 100644 (file)
@@ -978,12 +978,12 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
      bool no_leading_period, int flags, size_t alloca_used)
 {
   const CHAR *startp;
-  size_t level;
+  ptrdiff_t level;
   struct patternlist
   {
     struct patternlist *next;
     CHAR malloced;
-    CHAR str[FLEXIBLE_ARRAY_MEMBER];
+    CHAR str __flexarr;
   } *list = NULL;
   struct patternlist **lastp = &list;
   size_t pattern_len = STRLEN (pattern);
@@ -994,7 +994,7 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
 
   /* Parse the pattern.  Store the individual parts in the list.  */
   level = 0;
-  for (startp = p = pattern + 1; ; ++p)
+  for (startp = p = pattern + 1; level >= 0; ++p)
     if (*p == L_('\0'))
       {
         /* This is an invalid pattern.  */
@@ -1065,7 +1065,6 @@ EXT (INT opt, const CHAR *pattern, const CHAR *string, const CHAR *string_end,
             *lastp = newp;                                                    \
             lastp = &newp->next
             NEW_PATTERN;
-            break;
           }
       }
     else if (*p == L_('|'))
index a094c1fa761a79358b75c0ec6f689f5b24c608e0..1d58689cfda63a09f82f6f04cf66d91885eb05c4 100644 (file)
@@ -52,5 +52,15 @@ main ()
    */
   ASSERT (res = fnmatch ("[/b", "[/b", 0) == 0);
 
+  ASSERT (fnmatch ("[[:alpha:]'[:alpha:]\0]", "a", 0) == FNM_NOMATCH);
+  ASSERT (fnmatch ("[a[.\0.]]", "a", 0) == FNM_NOMATCH);
+#ifdef FNM_EXTMATCH
+  ASSERT (fnmatch ("**(!()", "**(!()", FNM_EXTMATCH) == 0);
+#endif
+#ifdef FNM_LEADING_DIR
+  ASSERT (fnmatch ("x?y", "x/y/z", FNM_PATHNAME | FNM_LEADING_DIR)
+          == FNM_NOMATCH);
+#endif
+
   return 0;
 }