Make compiling a no-op if it's attempted before adding any patterns. Fixes #485. Change-Id: Id7900ab2d034432016d425aeceb60a814225f10e Reviewed-on: https://code-review.googlesource.com/c/re2/+/62872 Reviewed-by: Paul Wankadia <junyer@google.com> Reviewed-by: Alex Chernyakhovsky <achernya@google.com>
diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc index 49cf686..1ce26a3 100644 --- a/re2/filtered_re2.cc +++ b/re2/filtered_re2.cc
@@ -70,8 +70,9 @@ return; } + // Similarly to PrefilterTree::Compile(), make compiling + // a no-op if it's attempted before adding any patterns. if (re2_vec_.empty()) { - LOG(ERROR) << "Compile called before Add."; return; }
diff --git a/re2/prefilter_tree.cc b/re2/prefilter_tree.cc index 3afb241..299a680 100644 --- a/re2/prefilter_tree.cc +++ b/re2/prefilter_tree.cc
@@ -57,8 +57,9 @@ // Some legacy users of PrefilterTree call Compile() before // adding any regexps and expect Compile() to have no effect. - if (prefilter_vec_.empty()) + if (prefilter_vec_.empty()) { return; + } compiled_ = true; @@ -272,8 +273,9 @@ // Some legacy users of PrefilterTree call Compile() before // adding any regexps and expect Compile() to have no effect. // This kludge is a counterpart to that kludge. - if (prefilter_vec_.empty()) + if (prefilter_vec_.empty()) { return; + } LOG(ERROR) << "RegexpsGivenStrings called before Compile."; for (size_t i = 0; i < prefilter_vec_.size(); i++)