Fall back to NFA execution when compiling the reverse Prog failed.
Change-Id: I7336a7d7ac3310dc9a567239f898d89394803058
Reviewed-on: https://code-review.googlesource.com/c/re2/+/52532
Reviewed-by: Paul Wankadia <junyer@google.com>
diff --git a/re2/re2.cc b/re2/re2.cc
index 71b66de..ecea782 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -678,8 +678,11 @@
// we already know where the match must end! Instead, the reverse DFA
// can say whether there is a match and (optionally) where it starts.
Prog* prog = ReverseProg();
- if (prog == NULL)
- return false;
+ if (prog == NULL) {
+ // Fall back to NFA below.
+ skipped_test = true;
+ break;
+ }
if (!prog->SearchDFA(subtext, text, Prog::kAnchored,
Prog::kLongestMatch, matchp, &dfa_failed, NULL)) {
if (dfa_failed) {
@@ -717,8 +720,11 @@
// match started. Run the regexp backward from match.end()
// to find the longest possible match -- that's where it started.
Prog* prog = ReverseProg();
- if (prog == NULL)
- return false;
+ if (prog == NULL) {
+ // Fall back to NFA below.
+ skipped_test = true;
+ break;
+ }
if (!prog->SearchDFA(match, text, Prog::kAnchored,
Prog::kLongestMatch, &match, &dfa_failed, NULL)) {
if (dfa_failed) {