Skip to content

Commit

Permalink
Make Regexp::Simplify() return a null pointer when stopped early.
Browse files Browse the repository at this point in the history
Change-Id: I19e447e6c7dec34201299a12104e72bf7e792a9e
Reviewed-on: https://code-review.googlesource.com/c/re2/+/57570
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Jul 14, 2020
1 parent fe8a81a commit ca11026
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions re2/prefilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,15 @@ Prefilter* Prefilter::FromRegexp(Regexp* re) {
return NULL;

Regexp* simple = re->Simplify();
Prefilter::Info *info = BuildInfo(simple);
if (simple == NULL)
return NULL;

Prefilter::Info* info = BuildInfo(simple);
simple->Decref();
if (info == NULL)
return NULL;

Prefilter* m = info->TakeMatch();

delete info;
return m;
}
Expand Down
14 changes: 11 additions & 3 deletions re2/simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ bool Regexp::SimplifyRegexp(const StringPiece& src, ParseFlags flags,
Regexp* sre = re->Simplify();
re->Decref();
if (sre == NULL) {
// Should not happen, since Simplify never fails.
LOG(ERROR) << "Simplify failed on " << src;
if (status) {
status->set_code(kRegexpInternalError);
status->set_error_arg(src);
Expand Down Expand Up @@ -180,10 +178,20 @@ Regexp* Regexp::Simplify() {
CoalesceWalker cw;
Regexp* cre = cw.Walk(this, NULL);
if (cre == NULL)
return cre;
return NULL;
if (cw.stopped_early()) {
cre->Decref();
return NULL;
}
SimplifyWalker sw;
Regexp* sre = sw.Walk(cre, NULL);
cre->Decref();
if (sre == NULL)
return NULL;
if (sw.stopped_early()) {
sre->Decref();
return NULL;
}
return sre;
}

Expand Down

0 comments on commit ca11026

Please sign in to comment.