This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Fix for bug-regex11.c
- From: Isamu Hasegawa <isamu at yamato dot ibm dot com>
- To: Ulrich Drepper <drepper at redhat dot com>, Jakub Jelinek <jakub at redhat dot com>
- Cc: Roland McGrath <roland at redhat dot com>, Jack Howarth <howarth at bromo dot med dot uc dot edu>, libc-alpha at sources dot redhat dot com, isamu at yamato dot ibm dot com, shoji at jp dot ibm dot com
- Date: Tue, 10 Sep 2002 23:58:25 +0900
- Subject: [PATCH] Fix for bug-regex11.c
- References: <200209041334.JAA00053@bromo.msbb.uc.edu>
Hi,
Attached patch seems to fix the bug showed by bug-regex11.c (and contains
a minor optimization). Is it appropriate?
2002-09-10 Isamu Hasegawa <isamu@yamato.ibm.com>
* posix/regexec.c (build_trtable): Fix the destination of
newline to prevent wrong states from overwriting.
Append break statements to optimization.
Thanks,
--
Isamu Hasegawa
IBM Japan, Ltd.
--- regexec.c.old 2002-09-10 23:40:40.000000000 +0900
+++ regexec.c 2002-09-10 23:39:13.000000000 +0900
@@ -1860,27 +1860,51 @@ build_trtable (preg, state, fl_search)
}
/* Update the transition table. */
+ /* For all characters ch...: */
for (i = 0, ch = 0; i < BITSET_UINTS; ++i)
for (j = 0; j < UINT_BITS; ++j, ++ch)
if ((acceptable[i] >> j) & 1)
{
+ /* The current state accepts the character ch. */
if (IS_WORD_CHAR (ch))
{
for (k = 0; k < ndests; ++k)
if ((dests_ch[k][i] >> j) & 1)
- trtable[ch] = dest_states_word[k];
+ {
+ /* k-th destination accepts the word character ch. */
+ trtable[ch] = dest_states_word[k];
+ /* There must be only one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ break;
+ }
}
else /* not WORD_CHAR */
{
for (k = 0; k < ndests; ++k)
if ((dests_ch[k][i] >> j) & 1)
- trtable[ch] = dest_states[k];
+ {
+ /* k-th destination accepts the non-word character ch. */
+ trtable[ch] = dest_states[k];
+ /* There must be only one destination which accepts
+ character ch. See group_nodes_into_DFAstates. */
+ break;
+ }
}
}
/* new line */
- for (k = 0; k < ndests; ++k)
- if (bitset_contain (acceptable, NEWLINE_CHAR))
- trtable[NEWLINE_CHAR] = dest_states_nl[k];
+ if (bitset_contain (acceptable, NEWLINE_CHAR))
+ {
+ /* The current state accepts newline character. */
+ for (k = 0; k < ndests; ++k)
+ if (bitset_contain (dests_ch[k], NEWLINE_CHAR))
+ {
+ /* k-th destination accepts newline character. */
+ trtable[NEWLINE_CHAR] = dest_states_nl[k];
+ /* There must be only one destination which accepts
+ newline. See group_nodes_into_DFAstates. */
+ break;
+ }
+ }
re_free (dest_states_nl);
re_free (dest_states_word);