[PATCH] Fix for bug-regex11.c
Isamu Hasegawa
isamu@yamato.ibm.com
Tue Sep 10 07:58:00 GMT 2002
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);
More information about the Libc-alpha
mailing list