From d6c2045dd99ec8d66dfca342c7eff37a3fcd1f61 Mon Sep 17 00:00:00 2001 From: chrchr Date: Fri, 2 Feb 2024 17:38:03 +0100 Subject: [PATCH] Mock error message --- lib/checkstl.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 32091b55eab..a9bf016aee4 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -3119,10 +3119,16 @@ void CheckStl::knownEmptyContainer() void CheckStl::eraseIteratorOutOfBoundsError(const Token *ftok, const Token* itertok, const ValueFlow::Value* val) { - const std::string func = ftok ? ftok->str() : std::string("erase"); - const std::string iter = itertok ? itertok->expressionString() : std::string("it"); + if (!ftok || !itertok || !val) { + reportError(ftok, Severity::error, "eraseIteratorOutOfBounds", + "Calling function 'erase()' on the iterator 'iter' which is out of bounds.", CWE628, Certainty::normal); + reportError(ftok, Severity::warning, "eraseIteratorOutOfBoundsCond", + "Either the condition 'x' is redundant or function 'erase()' is called on the iterator 'iter' which is out of bounds.", CWE628, Certainty::normal); + } + const std::string& func = ftok->str(); + const std::string iter = itertok->expressionString(); - const bool isConditional = val && val->isPossible(); + const bool isConditional = val->isPossible(); std::string msg; if (isConditional) { msg = ValueFlow::eitherTheConditionIsRedundant(val->condition) + " or function '" + func + "()' is called on the iterator '" + iter + "' which is out of bounds.";