[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/10] regex: minor refactoring
From: |
Paul Eggert |
Subject: |
[PATCH 03/10] regex: minor refactoring |
Date: |
Fri, 5 Feb 2021 17:25:55 -0800 |
* lib/regexec.c (proceed_next_node): Use more-local decls.
---
ChangeLog | 3 +++
lib/regexec.c | 14 ++++++--------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6fcd5819f..fdc107673 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2021-02-05 Paul Eggert <eggert@cs.ucla.edu>
+ regex: minor refactoring
+ * lib/regexec.c (proceed_next_node): Use more-local decls.
+
regex: avoid undefined behavior
* lib/regexec.c (pop_fail_stack): If the stack is empty, return -1
instead of indulging in undefined behavior. This simplifies
diff --git a/lib/regexec.c b/lib/regexec.c
index f982e3aba..fdd2e373e 100644
--- a/lib/regexec.c
+++ b/lib/regexec.c
@@ -1215,19 +1215,17 @@ proceed_next_node (const re_match_context_t *mctx, Idx
nregs, regmatch_t *regs,
struct re_fail_stack_t *fs)
{
const re_dfa_t *const dfa = mctx->dfa;
- Idx i;
- bool ok;
if (IS_EPSILON_NODE (dfa->nodes[node].type))
{
re_node_set *cur_nodes = &mctx->state_log[*pidx]->nodes;
re_node_set *edests = &dfa->edests[node];
- Idx dest_node;
- ok = re_node_set_insert (eps_via_nodes, node);
+ bool ok = re_node_set_insert (eps_via_nodes, node);
if (__glibc_unlikely (! ok))
return -2;
- /* Pick up a valid destination, or return -1 if none
- is found. */
- for (dest_node = -1, i = 0; i < edests->nelem; ++i)
+
+ /* Pick a valid destination, or return -1 if none is found. */
+ Idx dest_node = -1;
+ for (Idx i = 0; i < edests->nelem; i++)
{
Idx candidate = edests->elems[i];
if (!re_node_set_contains (cur_nodes, candidate))
@@ -1289,7 +1287,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx
nregs, regmatch_t *regs,
if (naccepted == 0)
{
Idx dest_node;
- ok = re_node_set_insert (eps_via_nodes, node);
+ bool ok = re_node_set_insert (eps_via_nodes, node);
if (__glibc_unlikely (! ok))
return -2;
dest_node = dfa->edests[node].elems[0];
--
2.27.0
- [PATCH 01/10] regex: improve comments, Paul Eggert, 2021/02/05
- [PATCH 04/10] regex: make it easier to merge into glibc, Paul Eggert, 2021/02/05
- [PATCH 05/10] regex-tests: fix typo, Paul Eggert, 2021/02/05
- [PATCH 03/10] regex: minor refactoring,
Paul Eggert <=
- [PATCH 10/10] regex: fix comment location, Paul Eggert, 2021/02/05
- [PATCH 08/10] regex: debug check for set member duplicates, Paul Eggert, 2021/02/05
- [PATCH 02/10] regex: avoid undefined behavior, Paul Eggert, 2021/02/05
- [PATCH 06/10] regex: avoid duplicate in espilon closure, Paul Eggert, 2021/02/05
- [PATCH 07/10] regex: fix longstanding backref match bug, Paul Eggert, 2021/02/05
- [PATCH 09/10] regex-tests: add bug 11053 test, Paul Eggert, 2021/02/05