From 51e9430a0c000bc8b4710487e9b72d41842d53a6 Mon Sep 17 00:00:00 2001 From: DongHun Kwak Date: Wed, 23 Sep 2020 15:45:47 +0900 Subject: [PATCH] Imported Upstream version 20200801 --- re2/prefilter.cc | 5 +++-- re2/simplify.cc | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/re2/prefilter.cc b/re2/prefilter.cc index f61d54b..a47b312 100644 --- a/re2/prefilter.cc +++ b/re2/prefilter.cc @@ -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; } diff --git a/re2/simplify.cc b/re2/simplify.cc index 270f0ff..663d5fc 100644 --- a/re2/simplify.cc +++ b/re2/simplify.cc @@ -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); @@ -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; } -- 2.7.4