* [PATCH] Fix regexec.c get_subexp
@ 2003-12-30 19:31 Jakub Jelinek
2003-12-30 20:01 ` Ulrich Drepper
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2003-12-30 19:31 UTC (permalink / raw)
To: Ulrich Drepper; +Cc: Glibc hackers
Hi!
The last 2 testcases added here to bug-regex11.c (distilled from
scripts/output-format.sed) fail with glibc since 2003-11-18.
bkref_str is not buf + bkref_str_idx at all times, it increases
by sl_str_diff in each iteration.
2003-12-30 Jakub Jelinek <jakub@redhat.com>
* posix/regexec.c (get_subexp): Only set bkref_str after the first
loop, use buf + bkref_str_off in the loop instead.
* posix/bug-regex11.c (tests): Add 3 new tests.
* posix/regexec.c (clean_state_log_if_need): Rename to...
(clean_state_log_if_needed): ...this.
(transit_state_mb, get_subexp_sub): Adjust callers.
--- libc/posix/regexec.c.jj 2003-12-29 18:56:55.000000000 +0100
+++ libc/posix/regexec.c 2003-12-30 20:21:34.000000000 +0100
@@ -117,8 +117,8 @@ static reg_errcode_t sift_states_bkref (
re_match_context_t *mctx,
re_sift_context_t *sctx,
int str_idx, re_node_set *dest_nodes) internal_function;
-static reg_errcode_t clean_state_log_if_need (re_match_context_t *mctx,
- int next_state_log_idx) internal_function;
+static reg_errcode_t clean_state_log_if_needed (re_match_context_t *mctx,
+ int next_state_log_idx) internal_function;
static reg_errcode_t merge_state_array (re_dfa_t *dfa, re_dfastate_t **dst,
re_dfastate_t **src, int num) internal_function;
static re_dfastate_t *transit_state (reg_errcode_t *err, const regex_t *preg,
@@ -1553,7 +1553,7 @@ sift_states_backward (preg, mctx, sctx)
/* Helper functions. */
static reg_errcode_t
-clean_state_log_if_need (mctx, next_state_log_idx)
+clean_state_log_if_needed (mctx, next_state_log_idx)
re_match_context_t *mctx;
int next_state_log_idx;
{
@@ -2392,7 +2392,7 @@ transit_state_mb (preg, pstate, mctx)
dest_idx = re_string_cur_idx (mctx->input) + naccepted;
mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted
: mctx->max_mb_elem_len);
- err = clean_state_log_if_need (mctx, dest_idx);
+ err = clean_state_log_if_needed (mctx, dest_idx);
if (BE (err != REG_NOERROR, 0))
return err;
#ifdef DEBUG
@@ -2569,14 +2569,14 @@ get_subexp (preg, mctx, bkref_node, bkre
reg_errcode_t err;
re_sub_match_top_t *sub_top = mctx->sub_tops[sub_top_idx];
re_sub_match_last_t *sub_last;
- int sub_last_idx, sl_str;
+ int sub_last_idx, sl_str, bkref_str_off;
const char *bkref_str;
if (dfa->nodes[sub_top->node].opr.idx != subexp_num)
continue; /* It isn't related. */
sl_str = sub_top->str_idx;
- bkref_str = buf + bkref_str_idx;
+ bkref_str_off = bkref_str_idx;
/* At first, check the last node of sub expressions we already
evaluated. */
for (sub_last_idx = 0; sub_last_idx < sub_top->nlasts; ++sub_last_idx)
@@ -2587,23 +2587,24 @@ get_subexp (preg, mctx, bkref_node, bkre
/* The matched string by the sub expression match with the substring
at the back reference? */
if (sl_str_diff > 0
- && memcmp (bkref_str, buf + sl_str, sl_str_diff) != 0)
+ && memcmp (buf + bkref_str_off, buf + sl_str, sl_str_diff) != 0)
break; /* We don't need to search this sub expression any more. */
- bkref_str += sl_str_diff;
+ bkref_str_off += sl_str_diff;
sl_str += sl_str_diff;
err = get_subexp_sub (preg, mctx, sub_top, sub_last, bkref_node,
bkref_str_idx);
- /* Reload buf and bkref_str, since the preceding call might
- have reallocated the buffer. */
+ /* Reload buf, since the preceding call might have reallocated
+ the buffer. */
buf = (const char *) re_string_get_buffer (mctx->input);
- bkref_str = buf + bkref_str_idx;
if (err == REG_NOMATCH)
continue;
if (BE (err != REG_NOERROR, 0))
return err;
}
+ bkref_str = buf + bkref_str_off;
+
if (sub_last_idx < sub_top->nlasts)
continue;
if (sub_last_idx > 0)
@@ -2678,7 +2679,7 @@ get_subexp_sub (preg, mctx, sub_top, sub
if (BE (err != REG_NOERROR, 0))
return err;
to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx;
- clean_state_log_if_need (mctx, to_idx);
+ clean_state_log_if_needed (mctx, to_idx);
return REG_NOERROR;
}
--- libc/posix/bug-regex11.c.jj 2003-11-29 10:14:13.000000000 +0100
+++ libc/posix/bug-regex11.c 2003-12-30 20:21:15.000000000 +0100
@@ -69,6 +69,10 @@ struct
{ "a()d(b)\\1c\\2", "adbcb", REG_EXTENDED, 3, { { 0, 5 }, { 1, 1 }, { 2, 3 } } },
{ "a(b())\\2\\1", "abbbb", REG_EXTENDED, 3, { { 0, 3 }, { 1, 2 }, { 2, 2 } } },
{ "(bb())\\2\\1", "bbbb", REG_EXTENDED, 3, { { 0, 4 }, { 0, 2 }, { 2, 2 } } },
+ { "^([^,]*),\\1,\\1$", "a,a,a", REG_EXTENDED, 2, { { 0, 5 }, { 0, 1 } } },
+ { "^([^,]*),\\1,\\1$", "ab,ab,ab", REG_EXTENDED, 2, { { 0, 8 }, { 0, 2 } } },
+ { "^([^,]*),\\1,\\1,\\1$", "abc,abc,abc,abc", REG_EXTENDED, 2,
+ { { 0, 15 }, { 0, 3 } } },
{ "^(.?)(.?)(.?)(.?)(.?).?\\5\\4\\3\\2\\1$",
"level", REG_NOSUB | REG_EXTENDED, 0, { { -1, -1 } } },
{ "^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\\9\\8\\7\\6\\5\\4\\3\\2\\1$|^.?$",
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix regexec.c get_subexp
2003-12-30 19:31 [PATCH] Fix regexec.c get_subexp Jakub Jelinek
@ 2003-12-30 20:01 ` Ulrich Drepper
0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2003-12-30 20:01 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jakub Jelinek wrote:
> The last 2 testcases added here to bug-regex11.c (distilled from
> scripts/output-format.sed) fail with glibc since 2003-11-18.
> bkref_str is not buf + bkref_str_idx at all times, it increases
> by sl_str_diff in each iteration.
Looks good, I've applied it.
- --
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/8dkS2ijCOnn/RHQRAmhEAKCE1W9ItfQFXbMeBZws3J2+rZG9WgCdFQ3N
6hOVa8W15SkVLQ6A0lpJcsc=
=08Jb
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-12-30 20:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-30 19:31 [PATCH] Fix regexec.c get_subexp Jakub Jelinek
2003-12-30 20:01 ` 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).