Cppcheck
|
Check STL usage (invalidation of iterators, mismatching containers, etc) More...
#include <checkstl.h>
Public Member Functions | |
CheckStl () | |
This constructor is used when registering the CheckClass. More... | |
Public Member Functions inherited from Check | |
Check (const std::string &aname) | |
This constructor is used when registering the CheckClass. More... | |
virtual | ~Check () |
Check (const Check &)=delete | |
Check & | operator= (const Check &)=delete |
const std::string & | name () const |
class name, used to generate documentation More... | |
virtual FileInfo * | getFileInfo (const Tokenizer &, const Settings &) const |
virtual FileInfo * | loadFileInfoFromXml (const tinyxml2::XMLElement *xmlElement) const |
virtual bool | analyseWholeProgram (const CTU::FileInfo *ctu, const std::list< FileInfo * > &fileInfo, const Settings &, ErrorLogger &) |
Private Types | |
enum class | SubstrErrorType { EMPTY , COPY , PREFIX , PREFIX_CONCAT } |
Private Member Functions | |
CheckStl (const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) | |
This constructor is used when running checks. More... | |
void | runChecks (const Tokenizer &tokenizer, ErrorLogger *errorLogger) override |
run checks, the token list is not simplified More... | |
void | outOfBounds () |
Accessing container out of bounds using ValueFlow. More... | |
void | outOfBoundsIndexExpression () |
Accessing container out of bounds, following index expression. More... | |
void | stlOutOfBounds () |
Finds errors like this: for (unsigned ii = 0; ii <= foo.size(); ++ii) More... | |
void | negativeIndex () |
negative index for array like containers More... | |
void | iterators () |
Finds errors like this: for (it = foo.begin(); it != bar.end(); ++it) More... | |
void | invalidContainer () |
bool | checkIteratorPair (const Token *tok1, const Token *tok2) |
void | mismatchingContainers () |
Mismatching containers: std::find(foo.begin(), bar.end(), x) More... | |
void | mismatchingContainerIterator () |
void | erase () |
Dangerous usage of erase. More... | |
void | eraseCheckLoopVar (const Scope &scope, const Variable *var) |
void | stlBoundaries () |
bad condition. More... | |
void | if_find () |
if (a.find(x)) - possibly incorrect condition More... | |
void | checkFindInsert () |
void | size () |
Suggest using empty() instead of checking size() against zero for containers. More... | |
void | redundantCondition () |
Check for redundant condition 'if (ints.find(1) != ints.end()) ints.remove(123);'. More... | |
void | missingComparison () |
Missing inner comparison, when incrementing iterator inside loop Dangers: More... | |
void | string_c_str () |
Check for common mistakes when using the function string::c_str() More... | |
void | uselessCalls () |
Check calls that using them is useless More... | |
void | checkDereferenceInvalidIterator () |
Check for dereferencing an iterator that is invalid More... | |
void | checkDereferenceInvalidIterator2 () |
void | dereferenceErasedError (const Token *erased, const Token *deref, const std::string &itername, bool inconclusive) |
Dereferencing an erased iterator. More... | |
void | useStlAlgorithm () |
Look for loops that can replaced with std algorithms. More... | |
void | knownEmptyContainer () |
void | eraseIteratorOutOfBounds () |
void | checkMutexes () |
bool | isContainerSize (const Token *containerToken, const Token *expr) const |
bool | isContainerSizeGE (const Token *containerToken, const Token *expr) const |
void | missingComparisonError (const Token *incrementToken1, const Token *incrementToken2) |
void | string_c_strThrowError (const Token *tok) |
void | string_c_strError (const Token *tok) |
void | string_c_strReturn (const Token *tok) |
void | string_c_strParam (const Token *tok, nonneg int number, const std::string &argtype="std::string") |
void | string_c_strConstructor (const Token *tok, const std::string &argtype="std::string") |
void | string_c_strAssignment (const Token *tok, const std::string &argtype="std::string") |
void | string_c_strConcat (const Token *tok) |
void | string_c_strStream (const Token *tok) |
void | outOfBoundsError (const Token *tok, const std::string &containerName, const ValueFlow::Value *containerSize, const std::string &index, const ValueFlow::Value *indexValue) |
void | outOfBoundsIndexExpressionError (const Token *tok, const Token *index) |
void | stlOutOfBoundsError (const Token *tok, const std::string &num, const std::string &var, bool at) |
void | negativeIndexError (const Token *tok, const ValueFlow::Value &index) |
void | invalidIteratorError (const Token *tok, const std::string &iteratorName) |
void | iteratorsError (const Token *tok, const std::string &containerName1, const std::string &containerName2) |
void | iteratorsError (const Token *tok, const Token *containerTok, const std::string &containerName1, const std::string &containerName2) |
void | iteratorsError (const Token *tok, const Token *containerTok, const std::string &containerName) |
void | mismatchingContainerIteratorError (const Token *containerTok, const Token *iterTok, const Token *containerTok2) |
void | mismatchingContainersError (const Token *tok1, const Token *tok2) |
void | mismatchingContainerExpressionError (const Token *tok1, const Token *tok2) |
void | sameIteratorExpressionError (const Token *tok) |
void | stlBoundariesError (const Token *tok) |
void | if_findError (const Token *tok, bool str) |
void | checkFindInsertError (const Token *tok) |
void | sizeError (const Token *tok) |
void | redundantIfRemoveError (const Token *tok) |
void | invalidContainerLoopError (const Token *tok, const Token *loopTok, ErrorPath errorPath) |
void | invalidContainerError (const Token *tok, const Token *contTok, const ValueFlow::Value *val, ErrorPath errorPath) |
void | invalidContainerReferenceError (const Token *tok, const Token *contTok, ErrorPath errorPath) |
void | uselessCallsReturnValueError (const Token *tok, const std::string &varname, const std::string &function) |
void | uselessCallsSwapError (const Token *tok, const std::string &varname) |
void | uselessCallsSubstrError (const Token *tok, SubstrErrorType type) |
void | uselessCallsEmptyError (const Token *tok) |
void | uselessCallsRemoveError (const Token *tok, const std::string &function) |
void | uselessCallsConstructorError (const Token *tok) |
void | dereferenceInvalidIteratorError (const Token *deref, const std::string &iterName) |
void | dereferenceInvalidIteratorError (const Token *tok, const ValueFlow::Value *value, bool inconclusive) |
void | useStlAlgorithmError (const Token *tok, const std::string &algoName) |
void | knownEmptyContainerError (const Token *tok, const std::string &algo) |
void | eraseIteratorOutOfBoundsError (const Token *ftok, const Token *itertok, const ValueFlow::Value *val=nullptr) |
void | globalLockGuardError (const Token *tok) |
void | localMutexError (const Token *tok) |
void | getErrorMessages (ErrorLogger *errorLogger, const Settings *settings) const override |
get error messages More... | |
std::string | classInfo () const override |
get information about this class, used to generate documentation More... | |
Static Private Member Functions | |
static std::string | myName () |
Additional Inherited Members | |
Static Public Member Functions inherited from Check | |
static std::list< Check * > & | instances () |
List of registered check classes. More... | |
static void | writeToErrorList (const ErrorMessage &errmsg) |
Write given error to stdout in xml format. More... | |
Protected Member Functions inherited from Check | |
Check (std::string aname, const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) | |
This constructor is used when running checks. More... | |
void | reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg) |
report an error More... | |
void | reportError (const Token *tok, const Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) |
report an error More... | |
void | reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg) |
report an error More... | |
void | reportError (const std::list< const Token * > &callstack, Severity severity, const std::string &id, const std::string &msg, const CWE &cwe, Certainty certainty) |
report an error More... | |
void | reportError (const ErrorPath &errorPath, Severity severity, const char id[], const std::string &msg, const CWE &cwe, Certainty certainty) |
void | logChecker (const char id[]) |
log checker More... | |
ErrorPath | getErrorPath (const Token *errtok, const ValueFlow::Value *value, std::string bug) const |
bool | wrongData (const Token *tok, const char *str) |
Use WRONG_DATA in checkers when you check for wrong data. More... | |
Static Protected Member Functions inherited from Check | |
static std::string | getMessageId (const ValueFlow::Value &value, const char id[]) |
Protected Attributes inherited from Check | |
const Tokenizer *const | mTokenizer {} |
const Settings *const | mSettings {} |
ErrorLogger *const | mErrorLogger {} |
Check STL usage (invalidation of iterators, mismatching containers, etc)
Definition at line 45 of file checkstl.h.
|
strongprivate |
Enumerator | |
---|---|
EMPTY | |
COPY | |
PREFIX | |
PREFIX_CONCAT |
Definition at line 227 of file checkstl.h.
|
inline |
This constructor is used when registering the CheckClass.
Definition at line 48 of file checkstl.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 52 of file checkstl.h.
|
private |
Check for dereferencing an iterator that is invalid
Definition at line 2352 of file checkstl.cpp.
References Scope::classDef, dereferenceInvalidIteratorError(), Scope::eDo, Scope::eFor, Scope::eIf, Token::findmatch(), Token::findsimplematch(), Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Scope::isLoopScope(), Token::link(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), SymbolDatabase::scopeList, Settings::severity, Token::strAt(), Token::tokAt(), Scope::type, Token::varId(), and warning.
Referenced by runChecks().
|
private |
Definition at line 2416 of file checkstl.cpp.
References astIsIntegral(), Token::astParent(), Token::astSibling(), Settings::certainty, dereferenceInvalidIteratorError(), emptyString, Token::expressionString(), getLifetimeIteratorValue(), Token::hasKnownIntValue(), inconclusive, ValueFlow::Value::intvalue, SimpleEnableGroup< T >::isEnabled(), ValueFlow::Value::isImpossible(), ValueFlow::Value::isInconclusive(), ValueFlow::Value::isIteratorEndValue(), ValueFlow::Value::isIteratorStartValue(), ValueFlow::Value::isIteratorValue(), ValueFlow::Value::isLifetimeValue(), CheckNullPointer::isPointerDeRef(), Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), outOfBoundsError(), ValueFlow::Value::path, Tokenizer::tokens(), ValueFlow::Value::tokvalue, and Token::values().
Referenced by runChecks().
|
private |
Definition at line 1680 of file checkstl.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, checkFindInsertError(), Standards::cpp, Standards::CPP17, findInsertValue(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), ValueType::isIntegral(), isMapFind(), isSameExpression(), Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), performance, ValueType::pointer, Settings::severity, Token::simpleMatch(), Settings::standards, and Token::valueType().
Referenced by runChecks().
|
private |
Definition at line 1726 of file checkstl.cpp.
References Token::astParent(), Standards::cpp, Standards::CPP11, Standards::CPP17, CWE398, Token::expressionString(), Check::mSettings, normal, performance, Check::reportError(), Token::simpleMatch(), and Settings::standards.
Referenced by checkFindInsert(), and getErrorMessages().
Definition at line 747 of file checkstl.cpp.
References ValueFlow::Value::Address, astIsContainer(), astIsFloat(), astIsIntegral(), Token::astParent(), Token::expressionString(), getIteratorExpression(), getLifetimeIteratorValue(), isSameIteratorContainerExpression(), iteratorsError(), ValueFlow::Value::Lambda, ValueFlow::Value::lifetimeKind, Token::Match(), mismatchingContainerExpressionError(), mismatchingContainersError(), Check::mSettings, ValueFlow::Value::Object, and ValueFlow::Value::tokvalue.
Referenced by mismatchingContainers().
|
private |
Definition at line 3254 of file checkstl.cpp.
References Variable::declarationId(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), globalLockGuardError(), SimpleEnableGroup< T >::isEnabled(), Variable::isGlobal(), isLocalMutex(), isLockGuard(), isMutex(), Variable::isStatic(), localMutexError(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::scope(), Settings::severity, Token::tokAt(), Token::variable(), and warning.
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 289 of file checkstl.h.
|
private |
Dereferencing an erased iterator.
erased | token where the erase occurs |
deref | token where the dereference occurs |
itername | iterator name |
inconclusive | inconclusive flag |
Definition at line 394 of file checkstl.cpp.
References CWE664, error, inconclusive, normal, and Check::reportError().
Referenced by eraseCheckLoopVar(), getErrorMessages(), and iterators().
|
private |
Definition at line 2541 of file checkstl.cpp.
References CWE825, normal, Check::reportError(), and warning.
Referenced by checkDereferenceInvalidIterator(), checkDereferenceInvalidIterator2(), and getErrorMessages().
|
private |
Definition at line 2512 of file checkstl.cpp.
References ValueFlow::Value::condition, CWE825, ValueFlow::eitherTheConditionIsRedundant(), error, Token::expressionString(), Check::getErrorPath(), inconclusive, Settings::isEnabled(), ValueFlow::Value::isInconclusive(), ValueFlow::Value::isKnown(), Check::mSettings, normal, Check::reportError(), and warning.
|
private |
Dangerous usage of erase.
The iterator is invalidated by erase so it is bad to dereference it after the erase.
Definition at line 1379 of file checkstl.cpp.
References Scope::classDef, Scope::eFor, eraseCheckLoopVar(), Scope::eWhile, Tokenizer::getSymbolDatabase(), Token::isName(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mTokenizer, Token::previous(), SymbolDatabase::scopeList, Token::simpleMatch(), Token::tokAt(), Scope::type, and Token::variable().
Referenced by runChecks().
Definition at line 1400 of file checkstl.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Scope::classDef, Variable::declarationId(), dereferenceErasedError(), isIterator(), isVector(), Token::link(), Token::linkAt(), Token::Match(), Variable::nameToken(), Token::next(), Token::simpleMatch(), Token::str(), Token::tokAt(), and Token::varId().
Referenced by erase().
|
private |
Definition at line 3193 of file checkstl.cpp.
References astIsLHS(), Token::astParent(), ValueType::container, ValueFlow::Value::CONTAINER_SIZE, Library::Container::ERASE, eraseIteratorOutOfBoundsError(), SymbolDatabase::functionScopes, Library::Container::getAction(), getArguments(), Token::getKnownValue(), getOOBIterValue(), Tokenizer::getSymbolDatabase(), Check::logChecker(), Check::mTokenizer, Token::next(), Token::simpleMatch(), Token::str(), and Token::valueType().
Referenced by runChecks().
|
private |
Definition at line 3148 of file checkstl.cpp.
References ValueFlow::Value::condition, CWE628, ValueFlow::eitherTheConditionIsRedundant(), error, Token::expressionString(), ValueFlow::Value::isPossible(), normal, Check::reportError(), Token::str(), and warning.
Referenced by eraseIteratorOutOfBounds(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 245 of file checkstl.h.
References checkFindInsertError(), dereferenceErasedError(), dereferenceInvalidIteratorError(), emptyString, eraseIteratorOutOfBoundsError(), globalLockGuardError(), if_findError(), invalidContainerError(), invalidContainerLoopError(), invalidIteratorError(), iteratorsError(), knownEmptyContainerError(), localMutexError(), mismatchingContainerExpressionError(), mismatchingContainerIteratorError(), mismatchingContainersError(), missingComparisonError(), negativeIndexError(), outOfBoundsError(), redundantIfRemoveError(), sameIteratorExpressionError(), sizeError(), stlBoundariesError(), stlOutOfBoundsError(), string_c_strError(), string_c_strParam(), string_c_strReturn(), string_c_strThrowError(), uselessCallsEmptyError(), uselessCallsRemoveError(), uselessCallsReturnValueError(), uselessCallsSubstrError(), uselessCallsSwapError(), and useStlAlgorithmError().
|
private |
Definition at line 3240 of file checkstl.cpp.
References CWE833, normal, Check::reportError(), and warning.
Referenced by checkMutexes(), and getErrorMessages().
|
private |
if (a.find(x)) - possibly incorrect condition
Definition at line 1498 of file checkstl.cpp.
References Token::astOperand2(), Token::astParent(), Scope::classDef, Library::detectContainer(), Scope::eIf, Scope::eWhile, Library::Container::FIND, Library::Container::FIND_CONST, Token::findsimplematch(), Library::Container::getAction(), Tokenizer::getSymbolDatabase(), Library::Container::getYield(), if_findCompare(), if_findError(), SimpleEnableGroup< T >::isEnabled(), Library::Container::ITERATOR, Settings::library, Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextTemplateArgument(), performance, SymbolDatabase::scopeList, Settings::severity, Token::simpleMatch(), Library::Container::stdStringLike, Token::str(), Token::tokAt(), Scope::type, Library::Container::type_templateArgNo, Token::variable(), and warning.
Referenced by runChecks().
|
private |
Definition at line 1575 of file checkstl.cpp.
References Standards::cpp, Standards::CPP20, CWE398, CWE597, Check::mSettings, normal, performance, Check::reportError(), Settings::standards, and warning.
Referenced by getErrorMessages(), and if_find().
|
private |
Definition at line 1104 of file checkstl.cpp.
References assignExpr(), astIsContainer(), astIsLHS(), astIsRHS(), Token::astOperand1(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, endOfExpression(), SymbolDatabase::functionScopes, getInnerLifetime(), getLoopContainer(), Tokenizer::getSymbolDatabase(), invalidContainerError(), invalidContainerLoopError(), invalidContainerReferenceError(), isReturnScope(), isVariableDecl(), Settings::library, Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), reaches(), PathAnalysis::Info::tok, ValueFlow::Value::tokvalue, Token::variable(), and Token::varId().
Referenced by runChecks().
|
private |
Definition at line 1229 of file checkstl.cpp.
References CWE664, error, ValueFlow::Value::errorPath, inconclusive, ValueFlow::Value::isInconclusive(), ValueFlow::lifetimeMessage(), normal, and Check::reportError().
Referenced by getErrorMessages(), and invalidContainer().
|
private |
Definition at line 1214 of file checkstl.cpp.
References CWE664, error, normal, Check::reportError(), and Token::str().
Referenced by getErrorMessages(), and invalidContainer().
|
private |
Definition at line 1239 of file checkstl.cpp.
References CWE664, error, Token::expressionString(), Check::name(), normal, and Check::reportError().
Referenced by invalidContainer().
|
private |
Definition at line 358 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and iterators().
Definition at line 280 of file checkstl.cpp.
References Token::astOperand1(), ValueType::container, Library::Container::getYield(), isSameExpression(), Token::Match(), Check::mSettings, Token::previous(), Token::simpleMatch(), Library::Container::SIZE, Token::str(), and Token::valueType().
Referenced by isContainerSizeGE().
Definition at line 291 of file checkstl.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::getValueGE(), Token::hasKnownIntValue(), isContainerSize(), Check::mSettings, Token::str(), and Token::values().
Referenced by outOfBoundsIndexExpression().
|
private |
Finds errors like this: for (it = foo.begin(); it != bar.end(); ++it)
Definition at line 464 of file checkstl.cpp.
References Scope::bodyEnd, Settings::certainty, dereferenceErasedError(), Token::findsimplematch(), getContainerName(), Tokenizer::getSymbolDatabase(), inconclusive, invalidIteratorError(), SimpleEnableGroup< T >::isEnabled(), isIterator(), isVector(), iteratorsError(), Token::link(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), Token::previous(), Token::scope(), Token::simpleMatch(), skipMembers(), Token::str(), Token::strAt(), Token::tokAt(), Variable::typeStartToken(), Token::variable(), SymbolDatabase::variableList(), and Token::varId().
Referenced by runChecks().
|
private |
Definition at line 363 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by checkIteratorPair(), getErrorMessages(), and iterators().
|
private |
Definition at line 380 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
|
private |
Definition at line 371 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
|
private |
Definition at line 3105 of file checkstl.cpp.
References Token::astOperand2(), emptyString, SymbolDatabase::functionScopes, Library::getArgIteratorInfo(), getArguments(), Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), isKnownEmptyContainer(), Settings::isPremiumEnabled(), knownEmptyContainerError(), Settings::library, Token::link(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, Token::simpleMatch(), Token::str(), and style.
Referenced by runChecks().
|
private |
Definition at line 3074 of file checkstl.cpp.
References astIsIterator(), CWE398, Token::expressionString(), normal, Check::reportError(), and style.
Referenced by getErrorMessages(), and knownEmptyContainer().
|
private |
Definition at line 3247 of file checkstl.cpp.
References CWE667, normal, Check::reportError(), and warning.
Referenced by checkMutexes(), and getErrorMessages().
|
private |
Definition at line 675 of file checkstl.cpp.
References CWE664, Token::expressionString(), normal, Check::reportError(), and warning.
Referenced by checkIteratorPair(), and getErrorMessages().
|
private |
Definition at line 855 of file checkstl.cpp.
References astIsContainer(), astIsIterator(), astIsLHS(), Token::astOperand1(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Library::Container::ERASE, SymbolDatabase::functionScopes, Library::Container::getAction(), getArguments(), getLifetimeIteratorValue(), Tokenizer::getSymbolDatabase(), Library::Container::INSERT, ValueFlow::Value::isKnown(), isSameIteratorContainerExpression(), ValueType::ITERATOR, ValueFlow::Value::Iterator, ValueFlow::Value::lifetimeKind, Check::logChecker(), Token::Match(), mismatchingContainerIteratorError(), Check::mSettings, Check::mTokenizer, Token::next(), Token::simpleMatch(), Token::str(), and ValueFlow::Value::tokvalue.
Referenced by runChecks().
|
private |
Definition at line 649 of file checkstl.cpp.
References CWE664, error, Token::expressionString(), normal, and Check::reportError().
Referenced by getErrorMessages(), and mismatchingContainerIterator().
|
private |
Mismatching containers: std::find(foo.begin(), bar.end(), x)
Definition at line 795 of file checkstl.cpp.
References Scope::bodyEnd, Scope::bodyStart, checkIteratorPair(), Library::ArgumentChecks::IteratorInfo::container, SymbolDatabase::functionScopes, Library::getArgIteratorInfo(), getArguments(), Tokenizer::getSymbolDatabase(), isSameExpression(), Settings::library, Check::logChecker(), Token::Match(), mismatchingContainersError(), Check::mSettings, Check::mTokenizer, Token::next(), sameIteratorExpressionError(), and SymbolDatabase::variableList().
Referenced by runChecks().
Definition at line 663 of file checkstl.cpp.
References CWE664, error, Token::expressionString(), normal, and Check::reportError().
Referenced by checkIteratorPair(), getErrorMessages(), and mismatchingContainers().
|
private |
Missing inner comparison, when incrementing iterator inside loop Dangers:
Definition at line 1860 of file checkstl.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Scope::classDef, Scope::eFor, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Token::linkAt(), Check::logChecker(), Token::Match(), missingComparisonError(), Check::mSettings, Check::mTokenizer, Token::next(), SymbolDatabase::scopeList, Settings::severity, Token::simpleMatch(), Token::tokAt(), Scope::type, and warning.
Referenced by runChecks().
|
private |
Definition at line 1924 of file checkstl.cpp.
References CWE834, Token::linenr(), normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and missingComparison().
|
inlinestaticprivate |
Definition at line 285 of file checkstl.h.
|
private |
negative index for array like containers
Definition at line 1341 of file checkstl.cpp.
References Library::Container::arrayLike_indexOp, Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, Library::detectContainer(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Variable::nameToken(), negativeIndexError(), Token::next(), Variable::typeStartToken(), and Token::variable().
Referenced by runChecks().
|
private |
Definition at line 1365 of file checkstl.cpp.
References ValueFlow::Value::condition, CWE786, ValueFlow::eitherTheConditionIsRedundant(), error, ValueFlow::Value::errorSeverity(), Check::getErrorPath(), inconclusive, ValueFlow::Value::intvalue, ValueFlow::Value::isInconclusive(), ValueFlow::Value::isKnown(), normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and negativeIndex().
|
private |
Accessing container out of bounds using ValueFlow.
Definition at line 133 of file checkstl.cpp.
References astIsIterator(), Token::astParent(), astParentSkipParens(), Settings::certainty, containerAppendsElement(), containerPopsElement(), containerYieldsElement(), Token::expressionString(), ValueFlow::findValue(), SymbolDatabase::functionScopes, getContainerIndex(), getLibraryContainer(), Tokenizer::getSymbolDatabase(), Token::hasKnownIntValue(), Token::hasKnownValue(), inconclusive, SimpleEnableGroup< T >::isEnabled(), ValueFlow::isOutOfBounds(), Check::logChecker(), Check::mSettings, Check::mTokenizer, Token::next(), outOfBoundsError(), Settings::severity, Token::simpleMatch(), Library::Container::stdAssociativeLike, Token::values(), and warning.
Referenced by runChecks().
|
private |
Definition at line 221 of file checkstl.cpp.
References ValueFlow::Value::condition, CWE398, ValueFlow::eitherTheConditionIsRedundant(), error, ValueFlow::Value::errorSeverity(), Token::expressionString(), Check::getErrorPath(), inconclusive, indexValueString(), ValueFlow::Value::intvalue, ValueFlow::Value::isInconclusive(), ValueFlow::Value::isPossible(), ValueType::ITERATOR, normal, Check::reportError(), ValueType::type, Token::valueType(), and warning.
Referenced by checkDereferenceInvalidIterator2(), getErrorMessages(), and outOfBounds().
|
private |
Accessing container out of bounds, following index expression.
Definition at line 320 of file checkstl.cpp.
References Library::Container::arrayLike_indexOp, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), isContainerSizeGE(), Check::logChecker(), Token::Match(), Check::mTokenizer, Token::next(), outOfBoundsIndexExpressionError(), and Library::Container::stdStringLike.
Referenced by runChecks().
Definition at line 340 of file checkstl.cpp.
References CWE398, error, Token::expressionString(), normal, Check::reportError(), and Token::str().
Referenced by outOfBoundsIndexExpression().
|
private |
Check for redundant condition 'if (ints.find(1) != ints.end()) ints.remove(123);'.
Definition at line 1819 of file checkstl.cpp.
References Scope::classDef, Scope::eIf, Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, redundantIfRemoveError(), SymbolDatabase::scopeList, Settings::severity, Token::str(), style, Token::tokAt(), and Scope::type.
Referenced by runChecks().
|
private |
Definition at line 1852 of file checkstl.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by getErrorMessages(), and redundantCondition().
|
inlineoverrideprivatevirtual |
run checks, the token list is not simplified
Implements Check.
Definition at line 56 of file checkstl.h.
References checkDereferenceInvalidIterator(), checkDereferenceInvalidIterator2(), checkFindInsert(), checkMutexes(), erase(), eraseIteratorOutOfBounds(), Tokenizer::getSettings(), if_find(), invalidContainer(), Tokenizer::isCPP(), iterators(), knownEmptyContainer(), mismatchingContainerIterator(), mismatchingContainers(), missingComparison(), negativeIndex(), outOfBounds(), outOfBoundsIndexExpression(), redundantCondition(), size(), stlBoundaries(), stlOutOfBounds(), string_c_str(), uselessCalls(), and useStlAlgorithm().
|
private |
Definition at line 684 of file checkstl.cpp.
References CWE664, normal, Check::reportError(), and style.
Referenced by getErrorMessages(), and mismatchingContainers().
|
private |
Suggest using empty() instead of checking size() against zero for containers.
Item 4 from Scott Meyers book "Effective STL".
Definition at line 1758 of file checkstl.cpp.
References Scope::bodyEnd, Scope::bodyStart, Standards::cpp, Standards::CPP11, Token::eLogicalOp, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Token::isArithmeticalOp(), isCpp03ContainerSizeSlow(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), performance, Token::previous(), Settings::severity, sizeError(), Settings::standards, Token::str(), Token::strAt(), Token::tokAt(), and Token::tokType().
Referenced by runChecks().
|
private |
Definition at line 1807 of file checkstl.cpp.
References CWE398, normal, performance, Check::reportError(), and Token::str().
Referenced by getErrorMessages(), and size().
|
private |
bad condition.
. "it < alist.end()"
Definition at line 1444 of file checkstl.cpp.
References Scope::bodyEnd, Variable::declarationId(), Library::detectIterator(), Tokenizer::getSymbolDatabase(), Scope::isExecutable(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Variable::nameToken(), Token::next(), Library::Container::opLessAllowed, Variable::scope(), stlBoundariesError(), Variable::typeStartToken(), and SymbolDatabase::variableList().
Referenced by runChecks().
|
private |
Definition at line 1469 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and stlBoundaries().
|
private |
Finds errors like this: for (unsigned ii = 0; ii <= foo.size(); ++ii)
Definition at line 1247 of file checkstl.cpp.
References Library::Container::arrayLike_indexOp, Token::astOperand1(), Token::astOperand2(), Library::Container::AT_INDEX, Scope::bodyEnd, Scope::bodyStart, Scope::classDef, ValueType::container, ValueFlow::Value::CONTAINER_SIZE, Scope::eFor, Scope::eIf, Tokenizer::getSymbolDatabase(), Library::Container::getYield(), Token::hasKnownValue(), Token::isComparisonOp(), Scope::isLoopScope(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mTokenizer, Token::next(), none, op1_and_op2, SymbolDatabase::scopeList, Token::simpleMatch(), Library::Container::SIZE, stlOutOfBoundsError(), Token::str(), Token::strAt(), Token::tokAt(), Scope::type, Token::valueType(), Token::varId(), and visitAstNodes().
Referenced by runChecks().
|
private |
Definition at line 1333 of file checkstl.cpp.
References CWE788, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and stlOutOfBounds().
|
private |
Check for common mistakes when using the function string::c_str()
Definition at line 1956 of file checkstl.cpp.
References Function::argumentList, Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, Settings::certainty, Scope::className, ValueType::CONTAINER, Scope::eFunction, Scope::function, Token::function(), Scope::functionList, Tokenizer::getSymbolDatabase(), Variable::getTypeName(), inconclusive, Variable::isConst(), SimpleEnableGroup< T >::isEnabled(), isLocal(), Variable::isPointer(), Variable::isReference(), Variable::isStlStringType(), isStlStringType(), Variable::isStlStringViewType(), Variable::isStlType(), ValueType::ITERATOR, Token::link(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), nonneg, performance, Token::previous(), SymbolDatabase::scopeList, Settings::severity, Token::simpleMatch(), Token::str(), Token::strAt(), string_c_strAssignment(), string_c_strConcat(), string_c_strConstructor(), string_c_strError(), string_c_strParam(), string_c_strReturn(), string_c_strStream(), string_c_strThrowError(), Token::tokAt(), Function::tokenDef, Scope::type, ValueType::type, Token::valueType(), and Token::variable().
Referenced by runChecks().
|
private |
Definition at line 2191 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by string_c_str().
|
private |
Definition at line 2198 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by string_c_str().
|
private |
Definition at line 2184 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by string_c_str().
|
private |
Definition at line 2164 of file checkstl.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and string_c_str().
|
private |
Definition at line 2176 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by getErrorMessages(), and string_c_str().
|
private |
Definition at line 2170 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by getErrorMessages(), and string_c_str().
|
private |
Definition at line 2205 of file checkstl.cpp.
References CWE704, normal, performance, and Check::reportError().
Referenced by string_c_str().
|
private |
Definition at line 2158 of file checkstl.cpp.
References error, and Check::reportError().
Referenced by getErrorMessages(), and string_c_str().
|
private |
Check calls that using them is useless
Definition at line 2226 of file checkstl.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, ValueType::CONTAINER, COPY, EMPTY, SymbolDatabase::functionScopes, getArguments(), Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), Variable::isStlType(), Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), performance, PREFIX, PREFIX_CONCAT, Token::previous(), Settings::severity, Token::simpleMatch(), Token::str(), Token::strAt(), Token::tokAt(), ValueType::type, Variable::typeEndToken(), Variable::typeStartToken(), uselessCallsConstructorError(), uselessCallsEmptyError(), uselessCallsRemoveError(), uselessCallsReturnValueError(), uselessCallsSubstrError(), uselessCallsSwapError(), Token::valueType(), Token::variable(), Token::varId(), and warning.
Referenced by runChecks().
|
private |
Definition at line 2330 of file checkstl.cpp.
References CWE398, normal, performance, Check::reportError(), and Token::str().
Referenced by uselessCalls().
|
private |
Definition at line 2336 of file checkstl.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and uselessCalls().
|
private |
Definition at line 2341 of file checkstl.cpp.
References CWE762, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and uselessCalls().
|
private |
Definition at line 2287 of file checkstl.cpp.
References CWE628, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and uselessCalls().
|
private |
Definition at line 2310 of file checkstl.cpp.
References COPY, CWE398, EMPTY, normal, performance, PREFIX, PREFIX_CONCAT, and Check::reportError().
Referenced by getErrorMessages(), and uselessCalls().
|
private |
Definition at line 2300 of file checkstl.cpp.
References CWE628, normal, performance, and Check::reportError().
Referenced by getErrorMessages(), and uselessCalls().
|
private |
Look for loops that can replaced with std algorithms.
Definition at line 2873 of file checkstl.cpp.
References accumulateBool(), accumulateBoolLiteral(), addByOne(), astIsBool(), astIsContainer(), Token::astOperand1(), Token::astOperand2(), Token::findmatch(), SymbolDatabase::functionScopes, getCondTok(), getInitTok(), getStepTok(), Tokenizer::getSymbolDatabase(), hasVarIds(), isConstExpression(), isEarlyExit(), SimpleEnableGroup< T >::isEnabled(), Token::isIncDecOp(), Settings::isPremiumEnabled(), Settings::library, Token::link(), Check::logChecker(), Token::Match(), minmaxCompare(), Check::mSettings, Check::mTokenizer, Token::next(), precedes(), Token::previous(), Settings::severity, Token::simpleMatch(), singleAssignInScope(), singleConditionalInScope(), singleIncrementInScope(), singleMemberCallInScope(), Token::str(), style, Token::tokAt(), ValueType::type, useStlAlgorithmError(), Token::valueType(), Token::variable(), and Token::varId().
Referenced by runChecks().
|
private |
Definition at line 2550 of file checkstl.cpp.
References CWE398, normal, Check::reportError(), and style.
Referenced by getErrorMessages(), and useStlAlgorithm().