James Youngman <[EMAIL PROTECTED]> writes: > Any ideas/suggestions?
Does the following untested patch fix things? It attempts to mimic what Bash does. *** fnmatch.c Fri May 13 23:03:58 2005 --- /tmp/fnmatch.c Tue Jun 7 00:02:03 2005 *************** fnmatch (const char *pattern, const char *** 319,372 **** wide characters. */ memset (&ps, '\0', sizeof (ps)); patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; ! if (__builtin_expect (patsize == 0, 0)) ! /* Something wrong. ! XXX Do we have to set `errno' to something which mbsrtows hasn't ! already done? */ ! return -1; ! assert (mbsinit (&ps)); ! strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; ! if (__builtin_expect (strsize == 0, 0)) ! /* Something wrong. ! XXX Do we have to set `errno' to something which mbsrtows hasn't ! already done? */ ! return -1; ! assert (mbsinit (&ps)); ! totsize = patsize + strsize; ! if (__builtin_expect (! (patsize <= totsize ! && totsize <= SIZE_MAX / sizeof (wchar_t)), ! 0)) { ! errno = ENOMEM; ! return -1; ! } ! ! /* Allocate room for the wide characters. */ ! if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) ! wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); ! else ! { ! wpattern = malloc (totsize * sizeof (wchar_t)); ! if (__builtin_expect (! wpattern, 0)) { ! errno = ENOMEM; ! return -1; } } - wstring = wpattern + patsize; - - /* Convert the strings into wide characters. */ - mbsrtowcs (wpattern, &pattern, patsize, &ps); - assert (mbsinit (&ps)); - mbsrtowcs (wstring, &string, strsize, &ps); - - res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, - flags & FNM_PERIOD, flags); - - if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) - free (wpattern); - return res; } # endif /* HANDLE_MULTIBYTE */ return internal_fnmatch (pattern, string, string + strlen (string), --- 319,369 ---- wide characters. */ memset (&ps, '\0', sizeof (ps)); patsize = mbsrtowcs (NULL, &pattern, 0, &ps) + 1; ! if (__builtin_expect (patsize != 0, 1)) { ! assert (mbsinit (&ps)); ! strsize = mbsrtowcs (NULL, &string, 0, &ps) + 1; ! if (__builtin_expect (strsize != 0, 1)) { ! assert (mbsinit (&ps)); ! totsize = patsize + strsize; ! if (__builtin_expect (! (patsize <= totsize ! && totsize <= SIZE_MAX / sizeof (wchar_t)), ! 0)) ! { ! errno = ENOMEM; ! return -1; ! } ! ! /* Allocate room for the wide characters. */ ! if (__builtin_expect (totsize < ALLOCA_LIMIT, 1)) ! wpattern = (wchar_t *) alloca (totsize * sizeof (wchar_t)); ! else ! { ! wpattern = malloc (totsize * sizeof (wchar_t)); ! if (__builtin_expect (! wpattern, 0)) ! { ! errno = ENOMEM; ! return -1; ! } ! } ! wstring = wpattern + patsize; ! ! /* Convert the strings into wide characters. */ ! mbsrtowcs (wpattern, &pattern, patsize, &ps); ! assert (mbsinit (&ps)); ! mbsrtowcs (wstring, &string, strsize, &ps); ! ! res = internal_fnwmatch (wpattern, wstring, wstring + strsize - 1, ! flags & FNM_PERIOD, flags); ! ! if (__builtin_expect (! (totsize < ALLOCA_LIMIT), 0)) ! free (wpattern); ! return res; } } } + # endif /* HANDLE_MULTIBYTE */ return internal_fnmatch (pattern, string, string + strlen (string), _______________________________________________ bug-gnulib mailing list bug-gnulib@gnu.org http://lists.gnu.org/mailman/listinfo/bug-gnulib