This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


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

[PATCH] Testcase for new regex bug


Hi!

The attached testcase fails for C (well, any MB_CUR_MAX == 1
locale) while it works properly in MB_CUR_MAX > 1 locales (and worked
in the old regex code too).
>From what I've been debugging so far, the difference is that
for MB_CUR_MAX > 1 it creates OP_ALT ( SIMPLE_BRACKET, COMPLEX_BRACKET )
for the range while for MB_CUR_MAX it only creates SIMPLE_BRACKET.
If either `|http' is added before `):)' or e.g. `p' is added after `^?#'
it works just fine.

2002-07-03  Jakub Jelinek  <jakub@redhat.com>

	* posix/bug-regex4.c (main): Remove duplicate setlocale.
	* posix/bug-regex6.c: New test.
	* posix/Makefile (tests): Add bug-regex6.
	(bug-regex6-ENV): Set LOCPATH.

--- libc/posix/bug-regex4.c.jj	Thu Aug 23 18:48:53 2001
+++ libc/posix/bug-regex4.c	Wed Jul  3 16:50:19 2002
@@ -35,7 +35,6 @@ main (void)
 
   setlocale (LC_ALL, "C");
 
-  setlocale (LC_ALL, "C");
   s = re_compile_pattern ("ab[cde]", 7, &regex);
   if (s != NULL)
     {
--- libc/posix/bug-regex6.c.jj	Wed Jul  3 16:50:42 2002
+++ libc/posix/bug-regex6.c	Wed Jul  3 17:12:28 2002
@@ -0,0 +1,74 @@
+/* Test for regexec.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+   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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sys/types.h>
+#include <regex.h>
+#include <locale.h>
+#include <stdio.h>
+
+int
+main (int argc, char *argv[])
+{
+  regex_t re;
+  regmatch_t mat[10];
+  int i, j, ret = 0;
+  char *locales[] = { "C", "de_DE.UTF-8" };
+  char *string = "http://www.regex.com/pattern/matching.html#intro";;
+  regmatch_t expect[10] = {
+    { 0, 48 }, { 0, 5 }, { 0, 4 }, { 5, 20 }, { 7, 20 }, { 20, 42 },
+    { -1, -1 }, { -1, -1 }, { 42, 48 }, { 43, 48 } };
+
+  for (i = 0; i < sizeof (locales) / sizeof (locales[0]); ++i)
+    {
+      if (setlocale (LC_ALL, locales[i]) == NULL)
+	{
+	  puts ("cannot set locale");
+	  ret = 1;
+	}
+      else if (regcomp (&re,
+			"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?",
+			REG_EXTENDED) != REG_NOERROR)
+	{
+	  puts ("cannot compile expression \"[a-f]*\"");
+	  ret = 1;
+	}
+      else if (regexec (&re, string, 10, mat, 0) == REG_NOMATCH)
+	{
+	  puts ("no match");
+	  ret = 1;
+	}
+      else
+	{
+	  if (! memcmp (mat, expect, sizeof (mat)))
+	    printf ("matching ok for %s locale\n", locales[i]);
+	  else
+	    {
+	      printf ("matching failed for %s locale:\n", locales[i]);
+	      ret = 1;
+	      for (j = 0; j < 9; ++j)
+		if (mat[j].rm_so != -1)
+		  printf ("%d: %.*s\n", j, mat[j].rm_eo - mat[j].rm_so,
+			  string + mat[j].rm_so);
+	    }
+	}
+    }
+
+  return ret;
+}
--- libc/posix/Makefile.jj	Thu Feb 28 12:32:04 2002
+++ libc/posix/Makefile	Wed Jul  3 17:14:19 2002
@@ -71,7 +71,7 @@ tests		:= tstgetopt testfnm runtests run
 		   tst-getlogin tst-mmap tst-getaddrinfo tst-truncate \
 		   tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \
 		   tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \
-		   tst-gnuglob tst-regex bug-regex5
+		   tst-gnuglob tst-regex bug-regex5 bug-regex6
 ifeq (yes,$(build-shared))
 test-srcs	:= globtest
 tests           += wordexp-test tst-exec tst-spawn
@@ -125,6 +125,7 @@ tst-regexloc-ENV = LOCPATH=$(common-objp
 bug-regex1-ENV = LOCPATH=$(common-objpfx)localedata
 tst-regex-ENV = LOCPATH=$(common-objpfx)localedata
 bug-regex5-ENV = LOCPATH=$(common-objpfx)localedata
+bug-regex6-ENV = LOCPATH=$(common-objpfx)localedata
 
 testcases.h: TESTS TESTS2C.sed
 	sed -f TESTS2C.sed < $< > $@T

	Jakub


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