public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: libc-hacker@sources.redhat.com
Subject: fnmatch and invalid multibyte characters
Date: Thu, 28 Nov 2002 06:07:00 -0000	[thread overview]
Message-ID: <jevg2h4wl5.fsf@sykes.suse.de> (raw)

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.

2002-11-28  Andreas Schwab  <schwab@suse.de>

	* posix/fnmatch.c (fnmatch): If conversion to wide character
	fails fall back to single byte matching.

--- posix/fnmatch.c.~1.47.~	2001-07-16 10:43:43.000000000 +0200
+++ posix/fnmatch.c	2002-11-25 15:21:12.000000000 +0100
@@ -325,6 +325,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;
       wchar_t *wpattern;
@@ -334,10 +335,8 @@ fnmatch (pattern, string, flags)
       memset (&ps, '\0', sizeof (ps));
       n = mbsrtowcs (NULL, &pattern, 0, &ps);
       if (__builtin_expect (n, 0) == (size_t) -1)
-	/* 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 = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
       assert (mbsinit (&ps));
       (void) mbsrtowcs (wpattern, &pattern, n + 1, &ps);
@@ -345,16 +344,17 @@ fnmatch (pattern, string, flags)
       assert (mbsinit (&ps));
       n = mbsrtowcs (NULL, &string, 0, &ps);
       if (__builtin_expect (n, 0) == (size_t) -1)
-	/* 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;
       wstring = (wchar_t *) alloca ((n + 1) * sizeof (wchar_t));
       assert (mbsinit (&ps));
       (void) mbsrtowcs (wstring, &string, n + 1, &ps);
 
       return internal_fnwmatch (wpattern, wstring, wstring + n,
 				flags & FNM_PERIOD, flags);
+
+ try_singlebyte:
+      pattern = orig_pattern;
     }
 # endif  /* mbstate_t and mbsrtowcs or _LIBC.  */
 

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

             reply	other threads:[~2002-11-28 14:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-28  6:07 Andreas Schwab [this message]
2002-11-28 10:31 ` Ulrich Drepper
2002-11-29  1:58   ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jevg2h4wl5.fsf@sykes.suse.de \
    --to=schwab@suse.de \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).