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] Fix re_match with non-zero start


Hi!

re_match is supposed to return the match length, while ATM it returns
start + match length.
Fixed thusly:

2002-08-26  Jakub Jelinek  <jakub@redhat.com>

	* posix/regexec.c (re_search_stub): Return correct match length
	if start != 0.
	* posix/bug-regex10.c: New test.
	* posix/Makefile (tests): Add bug-regex10.

--- libc/posix/regexec.c.jj	2002-07-29 15:14:54.000000000 +0200
+++ libc/posix/regexec.c	2002-08-26 15:13:03.000000000 +0200
@@ -371,8 +371,8 @@ re_search_stub (bufp, string, length, st
     {
       if (ret_len)
         {
-          assert (pmatch[0].rm_so == 0);
-          rval = pmatch[0].rm_eo;
+          assert (pmatch[0].rm_so == start);
+          rval = pmatch[0].rm_eo - start;
         }
       else
         rval = pmatch[0].rm_so;
--- libc/posix/bug-regex10.c.jj	2002-08-26 15:10:20.000000000 +0200
+++ libc/posix/bug-regex10.c	2002-08-26 15:12:18.000000000 +0200
@@ -0,0 +1,61 @@
+/* Test for re_match with non-zero start.
+   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 <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <regex.h>
+
+int
+main (void)
+{
+  struct re_pattern_buffer regex;
+  struct re_registers regs;
+  const char *s;
+  int match;
+  int result = 0;
+
+  regs.num_regs = 1;
+  memset (&regex, '\0', sizeof (regex));
+  s = re_compile_pattern ("[abc]*d", 7, &regex);
+  if (s != NULL)
+    {
+      puts ("re_compile_pattern return non-NULL value");
+      result = 1;
+    }
+  else
+    {
+      match = re_match (&regex, "foacabdxy", 9, 2, &regs);
+      if (match != 5)
+	{
+	  printf ("re_match returned %d, expected 5\n", match);
+	  result = 1;
+	}
+      else if (regs.start[0] != 2 || regs.end[0] != 7)
+	{
+	  printf ("re_match returned %d..%d, expected 2..7\n",
+		  regs.start[0], regs.end[0]);
+	  result = 1;
+	}
+	puts (" -> OK");
+    }
+
+  return result;
+}
--- libc/posix/Makefile.jj	2002-08-20 11:07:48.000000000 +0200
+++ libc/posix/Makefile	2002-08-26 15:13:55.000000000 +0200
@@ -72,7 +72,7 @@ tests		:= tstgetopt testfnm runtests run
 		   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 bug-regex6 bug-regex7 \
-		   bug-regex8 bug-regex9
+		   bug-regex8 bug-regex9 bug-regex10
 ifeq (yes,$(build-shared))
 test-srcs	:= globtest
 tests           += wordexp-test tst-exec tst-spawn

	Jakub


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