* [PATCH] Fix re_match with non-zero start
@ 2002-08-26 6:17 Jakub Jelinek
2002-08-26 15:47 ` Ulrich Drepper
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2002-08-26 6:17 UTC (permalink / raw)
To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers
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 (®ex, '\0', sizeof (regex));
+ s = re_compile_pattern ("[abc]*d", 7, ®ex);
+ if (s != NULL)
+ {
+ puts ("re_compile_pattern return non-NULL value");
+ result = 1;
+ }
+ else
+ {
+ match = re_match (®ex, "foacabdxy", 9, 2, ®s);
+ 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix re_match with non-zero start
2002-08-26 6:17 [PATCH] Fix re_match with non-zero start Jakub Jelinek
@ 2002-08-26 15:47 ` Ulrich Drepper
0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2002-08-26 15:47 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Roland McGrath, Glibc hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jakub Jelinek wrote:
> re_match is supposed to return the match length, while ATM it returns
> start + match length.
Thanks, I've applied the patch.
- --
- ---------------. ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Red Hat `--' drepper at redhat.com `------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE9aq/S2ijCOnn/RHQRAtiWAJ9G3dClLr+JYL/51eCrnTt1sEkAEgCfTr/O
NrPlhDg0pJ9Tpz9n/NhMShM=
=u76k
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-26 22:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-26 6:17 [PATCH] Fix re_match with non-zero start Jakub Jelinek
2002-08-26 15:47 ` Ulrich Drepper
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).