From 959b0c8bdbd737cdcba12e6db6a28da745c9e081 Mon Sep 17 00:00:00 2001 From: MarkLee131 Date: Mon, 30 Mar 2026 22:27:06 +0800 Subject: [PATCH] re2: add compiled_ check to AllMatches and AllPotentials FirstMatch() checks the compiled_ flag and logs DFATAL if Compile() has not been called. AllMatches() and AllPotentials() lack this check. This is consistent with the fix in commit 1250a99 (issue #484), where Filter.Match() in the Python bindings was changed to raise an error instead of crashing when called before Compile(). Add the same guard to AllMatches() and AllPotentials(). --- re2/filtered_re2.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/re2/filtered_re2.cc b/re2/filtered_re2.cc index f0995a10b..735f081d2 100644 --- a/re2/filtered_re2.cc +++ b/re2/filtered_re2.cc @@ -112,6 +112,11 @@ int FilteredRE2::FirstMatch(absl::string_view text, bool FilteredRE2::AllMatches(absl::string_view text, const std::vector& atoms, std::vector* matching_regexps) const { + if (!compiled_) { + ABSL_LOG(DFATAL) << "AllMatches called before Compile."; + matching_regexps->clear(); + return false; + } matching_regexps->clear(); std::vector regexps; prefilter_tree_->RegexpsGivenStrings(atoms, ®exps); @@ -123,6 +128,11 @@ bool FilteredRE2::AllMatches(absl::string_view text, void FilteredRE2::AllPotentials(const std::vector& atoms, std::vector* potential_regexps) const { + if (!compiled_) { + ABSL_LOG(DFATAL) << "AllPotentials called before Compile."; + potential_regexps->clear(); + return; + } prefilter_tree_->RegexpsGivenStrings(atoms, potential_regexps); }