From aba19be251eb1cccbf2d0db1b17aed729c56f6aa Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 15 Sep 2024 13:05:17 -0700 Subject: regex: bugfix: not taking full advantage of REGM_MATCH_DONE. * regex.c (nfa_has_transitions): The logical disjunction here is wrong. We would like to test whether a state has transitions if it is not an epsilon state. The code which uses this macro doesn't care about epsilon states, even though they have transitions; those are squeezed out by transitively closure. The wrong condition here makes the code think that a NFA set has transitions when it does not, preventing the result code REGM_MATCH_DONE to be produced which can spare a character from being consumed from a stream. --- regex.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regex.c b/regex.c index ab4155ed..670f9243 100644 --- a/regex.c +++ b/regex.c @@ -234,8 +234,8 @@ union nfa_state { #define nfa_accept_state_p(s) ((s)->a.kind == nfa_accept) #define nfa_empty_state_p(s) ((s)->a.kind == nfa_accept || \ (s)->a.kind == nfa_empty) -#define nfa_has_transitions(s) ((s)->a.kind != nfa_empty || \ - (s)->e.trans0 || (s)->e.trans1) +#define nfa_has_transitions(s) ((s)->a.kind != nfa_empty && \ + ((s)->e.trans0 || (s)->e.trans1)) struct nfa_machine { int is_nfa; /* common member */ -- cgit v1.2.3