| 3311 | } |
| 3312 | |
| 3313 | void 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 | |
| 3340 | static const ValueFlow::Value* getOOBIterValue(const Token* tok, const ValueFlow::Value* sizeVal) |
| 3341 | { |
no test coverage detected