glibc/glibc-fnmatch-multibyte.diff
Petr Baudis 9f6e6245a2 - Upgrade to latest release/2.11/master - glibc-2.11.2-dd2fde461e30
- Candidate tree for glibc-2.11.3
  - Multitude of various bug fixes

- Enable multi-arch routines support for ppc, ppc64, i686 and x86_64.
  Temporarily, AMD-optimized string routines are disabled. We will
  selectively re-enable them after some more careful benchmarking
  in the next few days.
  Note: In this glibc version, multi-arch routines DO NOT include
  the controversial backwards-copy memcpy().

OBS-URL: https://build.opensuse.org/package/show/Base:System/glibc?expand=0&rev=43
2010-11-16 01:47:23 +00:00

93 lines
3.0 KiB
Diff

When fnmatch detects an invalid multibyte character it should fall back to
single byte matching, so that "*" has a chance to match such a string.
Andreas.
Ported to glibc-2.11.3 by Petr Baudis.
2005-04-12 Andreas Schwab <schwab@suse.de>
* posix/fnmatch.c (fnmatch): If conversion to wide character
fails fall back to single byte matching.
Index: glibc-2.11.2/posix/fnmatch.c
===================================================================
--- glibc-2.11.2.orig/posix/fnmatch.c
+++ glibc-2.11.2/posix/fnmatch.c
@@ -333,6 +333,7 @@ fnmatch (pattern, string, flags)
# if HANDLE_MULTIBYTE
if (__builtin_expect (MB_CUR_MAX, 1) != 1)
{
+ const char *orig_pattern = pattern;
mbstate_t ps;
size_t n;
const char *p;
@@ -356,10 +357,8 @@ fnmatch (pattern, string, flags)
alloca_used);
n = mbsrtowcs (wpattern, &p, n + 1, &ps);
if (__builtin_expect (n == (size_t) -1, 0))
- /* Something wrong.
- XXX Do we have to set `errno' to something which mbsrtows hasn't
- already done? */
- return -1;
+ /* Something wrong. Fall back to single byte matching. */
+ goto try_singlebyte;
if (p)
{
memset (&ps, '\0', sizeof (ps));
@@ -371,10 +370,8 @@ fnmatch (pattern, string, flags)
prepare_wpattern:
n = mbsrtowcs (NULL, &pattern, 0, &ps);
if (__builtin_expect (n == (size_t) -1, 0))
- /* Something wrong.
- XXX Do we have to set `errno' to something which mbsrtows hasn't
- already done? */
- return -1;
+ /* Something wrong. Fall back to single byte matching. */
+ goto try_singlebyte;
wpattern_malloc = wpattern
= (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
assert (mbsinit (&ps));
@@ -396,14 +393,8 @@ fnmatch (pattern, string, flags)
alloca_used);
n = mbsrtowcs (wstring, &p, n + 1, &ps);
if (__builtin_expect (n == (size_t) -1, 0))
- {
- /* Something wrong.
- XXX Do we have to set `errno' to something which
- mbsrtows hasn't already done? */
- free_return:
- free (wpattern_malloc);
- return -1;
- }
+ /* Something wrong. Fall back to single byte matching. */
+ goto free_and_try_singlebyte;
if (p)
{
memset (&ps, '\0', sizeof (ps));
@@ -415,10 +406,8 @@ fnmatch (pattern, string, flags)
prepare_wstring:
n = mbsrtowcs (NULL, &string, 0, &ps);
if (__builtin_expect (n == (size_t) -1, 0))
- /* Something wrong.
- XXX Do we have to set `errno' to something which mbsrtows hasn't
- already done? */
- goto free_return;
+ /* Something wrong. Fall back to single byte matching. */
+ goto free_and_try_singlebyte;
wstring_malloc = wstring
= (wchar_t *) malloc ((n + 1) * sizeof (wchar_t));
@@ -439,6 +428,11 @@ fnmatch (pattern, string, flags)
free (wpattern_malloc);
return res;
+
+ free_and_try_singlebyte:
+ free(wpattern_malloc);
+ try_singlebyte:
+ pattern = orig_pattern;
}
# endif /* mbstate_t and mbsrtowcs or _LIBC. */