diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-31 13:35:53 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-12-31 13:43:59 -0800 |
commit | 453d130d1df3f251a6f2ad7cbc8cb6052c91d8fd (patch) | |
tree | 42c594979bf466adb1a962c8d58c695bfc0204a2 /lib/fnmatch_loop.c | |
parent | 4e609740b678cc8c0fcfcf966ff5e6ccb28c464b (diff) | |
download | gnulib-453d130d1df3f251a6f2ad7cbc8cb6052c91d8fd.tar.gz |
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.
Diffstat (limited to 'lib/fnmatch_loop.c')
-rw-r--r-- | lib/fnmatch_loop.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/fnmatch_loop.c b/lib/fnmatch_loop.c index c533107a2a..e5dac38b45 100644 --- a/lib/fnmatch_loop.c +++ b/lib/fnmatch_loop.c @@ -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_('|')) |