Skip to content

Commit

Permalink
Don't check kind_ == Prog::kManyMatch in DFA::InlinedSearchLoop().
Browse files Browse the repository at this point in the history
Instead, check in `DFA::Search()` that `matches` is null except when
using `RE2::Set`.

Change-Id: Iaf2a3b13acbf28c833ff93db874cc4dfa20a563a
Reviewed-on: https://code-review.googlesource.com/c/re2/+/62150
Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
Reviewed-by: Paul Wankadia <junyer@google.com>
  • Loading branch information
vovkos authored and junyer committed Nov 1, 2023
1 parent 2c25a64 commit 24d460a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions re2/dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) {
lastmatch = p;
if (ExtraDebug)
absl::FPrintF(stderr, "match @stx! [%s]\n", DumpState(s));
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
if (params->matches != NULL) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
if (id == MatchSep)
Expand Down Expand Up @@ -1484,7 +1484,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) {
lastmatch = p + 1;
if (ExtraDebug)
absl::FPrintF(stderr, "match @%d! [%s]\n", lastmatch - bp, DumpState(s));
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
if (params->matches != NULL) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
if (id == MatchSep)
Expand Down Expand Up @@ -1551,7 +1551,7 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) {
lastmatch = p;
if (ExtraDebug)
absl::FPrintF(stderr, "match @etx! [%s]\n", DumpState(s));
if (params->matches != NULL && kind_ == Prog::kManyMatch) {
if (params->matches != NULL) {
for (int i = s->ninst_ - 1; i >= 0; i--) {
int id = s->inst_[i];
if (id == MatchSep)
Expand Down Expand Up @@ -1767,6 +1767,8 @@ bool DFA::Search(absl::string_view text, absl::string_view context,
params.anchored = anchored;
params.want_earliest_match = want_earliest_match;
params.run_forward = run_forward;
// matches should be null except when using RE2::Set.
DCHECK(matches == NULL || kind_ == Prog::kManyMatch);
params.matches = matches;

if (!AnalyzeSearch(&params)) {
Expand Down

0 comments on commit 24d460a

Please sign in to comment.