* lib/regcomp.c (calc_eclosure_iter): Insert NODE into epsilon closure first rather than last. Otherwise, the epsilon closure might contain a duplicate of NODE. --- ChangeLog | 5 +++++ lib/regcomp.c | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog index f4583e0af..74304474b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2021-02-05 Paul Eggert <egg...@cs.ucla.edu> + regex: avoid duplicate in espilon closure + * lib/regcomp.c (calc_eclosure_iter): Insert NODE into epsilon + closure first rather than last. Otherwise, the epsilon closure + might contain a duplicate of NODE. + regex-tests: fix typo * tests/test-regex.c (main): Fix typo that would have caused an old test case to report incorrect values on failure. diff --git a/lib/regcomp.c b/lib/regcomp.c index d93698ae7..887e5b506 100644 --- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -1695,12 +1695,14 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) reg_errcode_t err; Idx i; re_node_set eclosure; - bool ok; bool incomplete = false; err = re_node_set_alloc (&eclosure, dfa->edests[node].nelem + 1); if (__glibc_unlikely (err != REG_NOERROR)) return err; + /* An epsilon closure includes itself. */ + eclosure.elems[eclosure.nelem++] = node; + /* This indicates that we are calculating this node now. We reference this value to avoid infinite loop. */ dfa->eclosures[node].nelem = -1; @@ -1753,10 +1755,6 @@ calc_eclosure_iter (re_node_set *new_set, re_dfa_t *dfa, Idx node, bool root) } } - /* An epsilon closure includes itself. */ - ok = re_node_set_insert (&eclosure, node); - if (__glibc_unlikely (! ok)) - return REG_ESPACE; if (incomplete && !root) dfa->eclosures[node].nelem = 0; else -- 2.27.0