This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix handling of collating elements in fnmatch (bug 17396, bug 16976)



On 09/01/2019 11:20, Andreas Schwab wrote:
> diff --git a/sysdeps/s390/wmemcmp.c b/posix/tst-fnmatch4.c
> similarity index 52%
> copy from sysdeps/s390/wmemcmp.c
> copy to posix/tst-fnmatch4.c
> index ec0b4027f8..dc13f89288 100644
> --- a/sysdeps/s390/wmemcmp.c
> +++ b/posix/tst-fnmatch4.c
> @@ -1,5 +1,5 @@
> -/* Multiple versions of wmemcmp.
> -   Copyright (C) 2015-2019 Free Software Foundation, Inc.
> +/* Test for fnmatch handling of collating elements
> +   Copyright (C) 2019 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
>     The GNU C Library is free software; you can redistribute it and/or
> @@ -16,23 +16,35 @@
>     License along with the GNU C Library; if not, see
>     <http://www.gnu.org/licenses/>.  */
>  
> -#include <ifunc-wmemcmp.h>
> -
> -#if HAVE_WMEMCMP_IFUNC
> -# include <wchar.h>
> -# include <ifunc-resolve.h>
> -
> -# if HAVE_WMEMCMP_C
> -extern __typeof (wmemcmp) WMEMCMP_C attribute_hidden;
> -# endif
> -
> -# if HAVE_WMEMCMP_Z13
> -extern __typeof (wmemcmp) WMEMCMP_Z13 attribute_hidden;
> -# endif
> -
> -s390_libc_ifunc_expr (wmemcmp, wmemcmp,
> -		      (HAVE_WMEMCMP_Z13 && (hwcap & HWCAP_S390_VX))
> -		      ? WMEMCMP_Z13
> -		      : WMEMCMP_DEFAULT
> -		      )
> -#endif
> +#include <stdio.h>
> +#include <locale.h>
> +#include <fnmatch.h>
> +
> +static int
> +do_test_locale (const char *locale)
> +{
> +  const char *pattern = "[[.ch.]]";
> +
> +  if (setlocale (LC_ALL, locale) == NULL)
> +    {
> +      printf ("could not set locale %s\n", locale);
> +      return 1;
> +    }
> +
> +  if (fnmatch (pattern, "ch", 0) != 0)
> +    {
> +      printf ("%s didn't match in locale %s\n", pattern, locale);
> +      return 1;
> +    }
> +
> +  return 0;
> +}

Maybe TEST_COMPARE on both check?

> +
> +static int
> +do_test (void)
> +{
> +  return (do_test_locale ("cs_CZ.ISO-8859-2")
> +	  || do_test_locale ("cs_CZ.UTF-8"));
> +}
> +
> +#include <support/test-driver.c>
> diff --git a/posix/tst-fnmatch5.c b/posix/tst-fnmatch5.c
> new file mode 100644
> index 0000000000..5ebff1f424
> --- /dev/null
> +++ b/posix/tst-fnmatch5.c
> @@ -0,0 +1,52 @@
> +/* Test for fnmatch handling of collating elements
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>.  */
> +
> +#include <fnmatch.h>
> +#include <locale.h>
> +#include <stdio.h>
> +#include <string.h>
> +
> +#define LENGTH 20000000
> +
> +static char pattern[LENGTH + 7];
> +
> +static int
> +do_test (void)
> +{
> +  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
> +    {
> +      puts ("could not set locale");
> +      return 1;
> +    }
> +  pattern[0] = '[';
> +  pattern[1] = '[';
> +  pattern[2] = '.';
> +  memset (pattern + 3, 'a', LENGTH);
> +  pattern[LENGTH + 3] = '.';
> +  pattern[LENGTH + 4] = ']';
> +  pattern[LENGTH + 5] = ']';
> +  int ret = fnmatch (pattern, "a", 0);
> +  if (ret == 0)
> +    {
> +      puts ("fnmatch returned 0 for invalid pattern");
> +      return 1;
> +    }
> +  return 0;
> +}
> +
> +#include <support/test-driver.c>

Same as before.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]