From: Benjamin Kramer Date: Sat, 9 Jul 2016 11:16:56 +0000 (+0000) Subject: [analyzer] Rewrite manual erase loop using remove_if. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3c0326176a64902b65dd1e06029e3b9b35438dd5;p=clang [analyzer] Rewrite manual erase loop using remove_if. No functionality change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274974 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp b/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp index 72a3b0a82d..4060f01582 100644 --- a/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/MallocOverflowSecurityChecker.cpp @@ -146,25 +146,24 @@ private: const Decl *getDecl(const MemberExpr *ME) { return ME->getMemberDecl(); } template - void Erase(const T1 *DR, std::function pred) { - theVecType::iterator i = toScanFor.end(); - theVecType::iterator e = toScanFor.begin(); - while (i != e) { - --i; - if (const T1 *DR_i = dyn_cast(i->variable)) { - if ((getDecl(DR_i) == getDecl(DR)) && pred(i)) - i = toScanFor.erase(i); - } - } + void Erase(const T1 *DR, + llvm::function_ref Pred = + [](const MallocOverflowCheck &) { return true; }) { + auto P = [this, DR, Pred](const MallocOverflowCheck &Check) { + if (const auto *CheckDR = dyn_cast(Check.variable)) + return getDecl(CheckDR) == getDecl(DR) && Pred(Check); + return false; + }; + toScanFor.erase(std::remove_if(toScanFor.begin(), toScanFor.end(), P), + toScanFor.end()); } void CheckExpr(const Expr *E_p) { - auto PredTrue = [](theVecType::iterator) -> bool { return true; }; const Expr *E = E_p->IgnoreParenImpCasts(); if (const DeclRefExpr *DR = dyn_cast(E)) - Erase(DR, PredTrue); + Erase(DR); else if (const auto *ME = dyn_cast(E)) { - Erase(ME, PredTrue); + Erase(ME); } } @@ -210,9 +209,9 @@ private: const Expr *E = lhs->IgnoreParenImpCasts(); auto pred = [assignKnown, numeratorKnown, - denomExtVal](theVecType::iterator i) { + denomExtVal](const MallocOverflowCheck &Check) { return assignKnown || - (numeratorKnown && (denomExtVal >= i->maxVal.getExtValue())); + (numeratorKnown && (denomExtVal >= Check.maxVal.getExtValue())); }; if (const DeclRefExpr *DR = dyn_cast(E))