MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / eraseIteratorOutOfBoundsError

Method eraseIteratorOutOfBoundsError

lib/checkstl.cpp:3313–3338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3311}
3312
3313void CheckStlImpl::eraseIteratorOutOfBoundsError(const Token *ftok, const Token* itertok, const ValueFlow::Value* val)
3314{
3315 if (!ftok || !itertok || !val) {
3316 reportError(ftok, Severity::error, "eraseIteratorOutOfBounds",
3317 "Calling function 'erase()' on the iterator 'iter' which is out of bounds.", CWE628, Certainty::normal);
3318 reportError(ftok, Severity::warning, "eraseIteratorOutOfBoundsCond",
3319 "Either the condition 'x' is redundant or function 'erase()' is called on the iterator 'iter' which is out of bounds.", CWE628, Certainty::normal);
3320 return;
3321 }
3322 const std::string& func = ftok->str();
3323 const std::string iter = itertok->expressionString();
3324
3325 const bool isConditional = val->isPossible();
3326 std::string msg;
3327 if (isConditional) {
3328 msg = ValueFlow::eitherTheConditionIsRedundant(val->condition) + " or function '" + func + "()' is called on the iterator '" + iter + "' which is out of bounds.";
3329 } else {
3330 msg = "Calling function '" + func + "()' on the iterator '" + iter + "' which is out of bounds.";
3331 }
3332
3333 const Severity severity = isConditional ? Severity::warning : Severity::error;
3334 const std::string id = isConditional ? "eraseIteratorOutOfBoundsCond" : "eraseIteratorOutOfBounds";
3335 reportError(ftok, severity,
3336 id,
3337 msg, CWE628, Certainty::normal);
3338}
3339
3340static const ValueFlow::Value* getOOBIterValue(const Token* tok, const ValueFlow::Value* sizeVal)
3341{

Callers 1

getErrorMessagesMethod · 0.80

Calls 4

isPossibleMethod · 0.80
reportErrorFunction · 0.70
strMethod · 0.45
expressionStringMethod · 0.45

Tested by

no test coverage detected