Cppcheck
|
#include "checkstl.h"
#include "astutils.h"
#include "errortypes.h"
#include "library.h"
#include "mathlib.h"
#include "pathanalysis.h"
#include "settings.h"
#include "standards.h"
#include "symboldatabase.h"
#include "token.h"
#include "tokenize.h"
#include "utils.h"
#include "valueflow.h"
#include "checknullpointer.h"
#include <algorithm>
#include <cassert>
#include <iterator>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
Go to the source code of this file.
Functions | |
static bool | isElementAccessYield (Library::Container::Yield yield) |
static bool | containerAppendsElement (const Library::Container *container, const Token *parent) |
static bool | containerYieldsElement (const Library::Container *container, const Token *parent) |
static bool | containerPopsElement (const Library::Container *container, const Token *parent) |
static const Token * | getContainerIndex (const Library::Container *container, const Token *parent) |
static const Token * | getContainerFromSize (const Library::Container *container, const Token *tok) |
static std::string | indexValueString (const ValueFlow::Value &indexValue, const std::string &containerName=emptyString) |
static const Token * | skipMembers (const Token *tok) |
static bool | isIterator (const Variable *var, bool &inconclusiveType) |
static std::string | getContainerName (const Token *containerToken) |
static bool | isVector (const Token *tok) |
static std::vector< const Token * > | getAddressContainer (const Token *tok) |
static bool | isSameIteratorContainerExpression (const Token *tok1, const Token *tok2, const Settings &settings, ValueFlow::Value::LifetimeKind kind=ValueFlow::Value::LifetimeKind::Iterator) |
static ValueFlow::Value | getLifetimeIteratorValue (const Token *tok, MathLib::bigint path=0) |
static const Token * | getInvalidMethod (const Token *tok) |
static const Token * | getLoopContainer (const Token *tok) |
static const ValueFlow::Value * | getInnerLifetime (const Token *tok, nonneg int id, ErrorPath *errorPath=nullptr, int depth=4) |
static const Token * | endOfExpression (const Token *tok) |
static bool | if_findCompare (const Token *const tokBack, bool stdStringLike) |
static std::pair< const Token *, const Token * > | isMapFind (const Token *tok) |
static const Token * | skipLocalVars (const Token *const tok) |
static const Token * | findInsertValue (const Token *tok, const Token *containerTok, const Token *keyTok, const Settings &settings) |
static bool | isCpp03ContainerSizeSlow (const Token *tok) |
Is container.size() slow? More... | |
static bool | isLocal (const Token *tok) |
static bool | isEarlyExit (const Token *start) |
static const Token * | singleStatement (const Token *start) |
static const Token * | singleAssignInScope (const Token *start, nonneg int varid, bool &input, bool &hasBreak, const Settings &settings) |
static const Token * | singleMemberCallInScope (const Token *start, nonneg int varid, bool &input, const Settings &settings) |
static const Token * | singleIncrementInScope (const Token *start, nonneg int varid, bool &input) |
static const Token * | singleConditionalInScope (const Token *start, nonneg int varid, const Settings &settings) |
static bool | addByOne (const Token *tok, nonneg int varid) |
static bool | accumulateBoolLiteral (const Token *tok, nonneg int varid) |
static bool | accumulateBool (const Token *tok, nonneg int varid) |
static bool | hasVarIds (const Token *tok, nonneg int var1, nonneg int var2) |
static std::string | flipMinMax (const std::string &algo) |
static std::string | minmaxCompare (const Token *condTok, nonneg int loopVar, nonneg int assignVar, bool invert=false) |
static bool | isKnownEmptyContainer (const Token *tok) |
static const ValueFlow::Value * | getOOBIterValue (const Token *tok, const ValueFlow::Value *sizeVal) |
static bool | isMutex (const Variable *var) |
static bool | isLockGuard (const Variable *var) |
static bool | isLocalMutex (const Variable *var, const Scope *scope) |
Variables | |
static const CWE | CWE398 (398U) |
static const CWE | CWE597 (597U) |
static const CWE | CWE628 (628U) |
static const CWE | CWE664 (664U) |
static const CWE | CWE667 (667U) |
static const CWE | CWE704 (704U) |
static const CWE | CWE762 (762U) |
static const CWE | CWE786 (786U) |
static const CWE | CWE788 (788U) |
static const CWE | CWE825 (825U) |
static const CWE | CWE833 (833U) |
static const CWE | CWE834 (834U) |
Definition at line 2689 of file checkstl.cpp.
References Token::Match(), and Token::simpleMatch().
Referenced by CheckStl::useStlAlgorithm().
Definition at line 2676 of file checkstl.cpp.
References Token::hasKnownIntValue(), Token::Match(), and Token::tokAt().
Referenced by CheckStl::useStlAlgorithm().
Definition at line 2661 of file checkstl.cpp.
References Token::getValue(), Token::hasKnownIntValue(), Token::Match(), and Token::tokAt().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 72 of file checkstl.cpp.
References Library::Container::CHANGE, Library::Container::CHANGE_INTERNAL, contains(), Library::Container::getAction(), Library::Container::INSERT, Token::Match(), Library::Container::PUSH, Library::Container::RESIZE, and Token::strAt().
Referenced by CheckStl::outOfBounds().
|
static |
Definition at line 97 of file checkstl.cpp.
References contains(), Library::Container::getAction(), Token::Match(), Library::Container::POP, and Token::strAt().
Referenced by CheckStl::outOfBounds().
|
static |
Definition at line 87 of file checkstl.cpp.
References Library::Container::getYield(), isElementAccessYield(), Token::Match(), and Token::strAt().
Referenced by CheckStl::outOfBounds().
Definition at line 1089 of file checkstl.cpp.
References Token::astParent(), Token::next(), nextAfterAstRightmostLeaf(), and Token::simpleMatch().
Referenced by CheckStl::invalidContainer().
|
static |
Definition at line 1646 of file checkstl.cpp.
References astIsIterator(), Token::astOperand1(), Token::astOperand2(), Token::astTop(), isSameExpression(), Token::Match(), Token::simpleMatch(), and skipLocalVars().
Referenced by CheckStl::checkFindInsert().
|
static |
Definition at line 2713 of file checkstl.cpp.
Referenced by minmaxCompare().
Definition at line 689 of file checkstl.cpp.
References Token::astOperand1(), Token::astOperand2(), ValueFlow::getLifetimeObjValues(), and Token::simpleMatch().
Referenced by isSameIteratorContainerExpression().
|
static |
Definition at line 121 of file checkstl.cpp.
References Token::astOperand1(), Library::Container::getYield(), Token::Match(), Library::Container::SIZE, Token::strAt(), and Token::tokAt().
|
static |
Definition at line 107 of file checkstl.cpp.
References Library::Container::arrayLike_indexOp, Token::astOperand2(), Library::Container::AT_INDEX, Library::Container::getYield(), Token::Match(), Token::simpleMatch(), Library::Container::stdStringLike, Token::strAt(), and Token::tokAt().
Referenced by CheckStl::outOfBounds().
|
static |
Definition at line 442 of file checkstl.cpp.
References Token::Match(), Token::str(), and Token::tokAt().
Referenced by CheckStl::iterators().
|
static |
Definition at line 1056 of file checkstl.cpp.
References ValueFlow::Value::Address, contains(), ValueFlow::Value::Lambda, ValueFlow::Value::SubObject, and Token::values().
Referenced by CheckStl::invalidContainer().
Definition at line 906 of file checkstl.cpp.
References astIsLHS(), Token::astParent(), Library::Container::CHANGE, Library::Container::CHANGE_INTERNAL, Library::Container::CLEAR, ValueType::container, Library::Container::ERASE, Library::Container::INSERT, Token::Match(), Library::Container::POP, Library::Container::PUSH, Library::Container::RESIZE, Token::str(), and Token::valueType().
|
static |
Definition at line 728 of file checkstl.cpp.
References ValueFlow::getLifetimeObjValues().
Referenced by CheckStl::checkDereferenceInvalidIterator2(), CheckStl::checkIteratorPair(), and CheckStl::mismatchingContainerIterator().
Definition at line 1046 of file checkstl.cpp.
References Token::astOperand2(), Token::next(), and Token::simpleMatch().
Referenced by CheckStl::invalidContainer().
|
static |
Definition at line 3175 of file checkstl.cpp.
References Token::values().
Referenced by CheckStl::eraseIteratorOutOfBounds().
Definition at line 2701 of file checkstl.cpp.
References Token::astOperand1(), and Token::astOperand2().
Referenced by minmaxCompare(), and CheckStl::useStlAlgorithm().
|
static |
Definition at line 1477 of file checkstl.cpp.
References Token::astOperand1(), Token::astOperand2(), Token::astParent(), Token::astSibling(), Token::getKnownIntValue(), Token::hasKnownIntValue(), Token::isArithmeticalOp(), Token::isAssignmentOp(), Token::isComparisonOp(), and Token::str().
Referenced by CheckStl::if_find().
|
static |
Definition at line 204 of file checkstl.cpp.
References ValueFlow::Value::bound, ValueFlow::Value::intvalue, ValueFlow::Value::isIteratorEndValue(), ValueFlow::Value::isIteratorStartValue(), ValueFlow::Value::isSymbolicValue(), and ValueFlow::Value::Lower.
Referenced by CheckStl::outOfBoundsError().
|
static |
Is container.size() slow?
Definition at line 1750 of file checkstl.cpp.
References Variable::isStlType(), and Token::variable().
Referenced by CheckStl::size().
|
static |
Definition at line 2556 of file checkstl.cpp.
References Token::findmatch(), Token::findsimplematch(), Token::link(), Token::next(), and Token::str().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 67 of file checkstl.cpp.
References Library::Container::AT_INDEX, contains(), and Library::Container::ITEM.
Referenced by containerYieldsElement().
|
static |
Definition at line 419 of file checkstl.cpp.
References Function::argCount(), Type::getFunction(), Variable::isLocal(), Token::Match(), Variable::nameToken(), Token::str(), Variable::type(), ValueType::type, Variable::typeEndToken(), and Token::valueType().
Referenced by Library::detectContainerInternal(), Library::detectContainerOrIterator(), CheckStl::eraseCheckLoopVar(), CheckStl::iterators(), parsedecl(), and SymbolDatabase::setValueTypeInTokenList().
|
static |
Definition at line 3090 of file checkstl.cpp.
References Token::values().
Referenced by CheckStl::knownEmptyContainer().
|
static |
Definition at line 1944 of file checkstl.cpp.
References Variable::isLocal(), Variable::isStatic(), and Token::variable().
Referenced by CheckStl::string_c_str().
Definition at line 3231 of file checkstl.cpp.
References isLockGuard(), Variable::isReference(), Variable::isRValueReference(), Variable::isStatic(), and Variable::scope().
Referenced by CheckStl::checkMutexes().
|
static |
Definition at line 3225 of file checkstl.cpp.
References Token::Match(), Variable::nameToken(), and Token::typeDecl().
Referenced by CheckStl::checkMutexes(), and isLocalMutex().
Definition at line 1588 of file checkstl.cpp.
References astIsContainer(), Token::astOperand1(), Token::astOperand2(), ValueType::container, Token::Match(), Token::simpleMatch(), Library::Container::stdAssociativeLike, and Token::valueType().
Referenced by CheckStl::checkFindInsert().
|
static |
Definition at line 3219 of file checkstl.cpp.
References Token::Match(), Variable::nameToken(), and Token::typeDecl().
Referenced by CheckStl::checkMutexes().
|
static |
Definition at line 706 of file checkstl.cpp.
References ValueFlow::Value::Address, astContainerYield(), astIsContainerOwned(), getAddressContainer(), isSameExpression(), isTemporary(), Library::Container::ITEM, ValueFlow::Value::Iterator, and Settings::library.
Referenced by CheckStl::checkIteratorPair(), and CheckStl::mismatchingContainerIterator().
|
static |
Definition at line 455 of file checkstl.cpp.
References Token::simpleMatch(), Variable::typeStartToken(), and Token::variable().
Referenced by CheckStl::eraseCheckLoopVar(), and CheckStl::iterators().
|
static |
Definition at line 2722 of file checkstl.cpp.
References Token::astOperand1(), flipMinMax(), hasVarIds(), and Token::Match().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 2585 of file checkstl.cpp.
References Token::astOperand1(), Token::findmatch(), isVariableChanged(), Token::Match(), Token::next(), Token::previous(), Token::simpleMatch(), singleStatement(), and Token::tokAt().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 2639 of file checkstl.cpp.
References Token::findmatch(), isVariableChanged(), Token::link(), Token::linkAt(), Token::next(), Token::simpleMatch(), and Token::str().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 2624 of file checkstl.cpp.
References Token::Match(), Token::next(), Token::str(), Token::tokAt(), and Token::varId().
Referenced by CheckStl::useStlAlgorithm().
|
static |
Definition at line 2602 of file checkstl.cpp.
References Token::astOperand1(), Token::findmatch(), isVariableChanged(), Token::link(), Token::linkAt(), Token::Match(), Token::next(), Token::simpleMatch(), Token::str(), and Token::tokAt().
Referenced by CheckStl::useStlAlgorithm().
Definition at line 2572 of file checkstl.cpp.
References Token::findsimplematch(), Token::link(), Token::next(), Token::simpleMatch(), and Token::str().
Referenced by singleAssignInScope().
Definition at line 1609 of file checkstl.cpp.
References Token::astOperand1(), Token::astTop(), Token::findsimplematch(), Token::isAssignmentOp(), Token::Match(), Variable::nameToken(), Token::next(), nextAfterAstRightmostLeaf(), Token::previous(), Variable::scope(), Token::scope(), Token::simpleMatch(), and Token::variable().
Referenced by findInsertValue().
Definition at line 412 of file checkstl.cpp.
References Token::Match(), and Token::tokAt().
Referenced by CheckStl::iterators().
|
static |
Referenced by CheckStl::checkFindInsertError(), CheckStl::if_findError(), CheckStl::knownEmptyContainerError(), CheckStl::outOfBoundsError(), CheckStl::outOfBoundsIndexExpressionError(), CheckStl::redundantIfRemoveError(), CheckStl::sizeError(), CheckStl::uselessCallsConstructorError(), CheckStl::uselessCallsEmptyError(), CheckStl::uselessCallsSubstrError(), and CheckStl::useStlAlgorithmError().
|
static |
Referenced by CheckStl::if_findError().
|
static |
|
static |
Referenced by CheckStl::dereferenceErasedError(), CheckStl::invalidContainerError(), CheckStl::invalidContainerLoopError(), CheckStl::invalidContainerReferenceError(), CheckStl::invalidIteratorError(), CheckStl::iteratorsError(), CheckStl::mismatchingContainerExpressionError(), CheckStl::mismatchingContainerIteratorError(), CheckStl::mismatchingContainersError(), CheckStl::sameIteratorExpressionError(), CheckStl::stlBoundariesError(), and CheckStl::string_c_strError().
|
static |
Referenced by CheckStl::localMutexError().
|
static |
|
static |
Referenced by CheckStl::uselessCallsRemoveError().
|
static |
Referenced by CheckStl::negativeIndexError().
|
static |
Referenced by CheckStl::stlOutOfBoundsError().
|
static |
Referenced by CheckStl::dereferenceInvalidIteratorError().
|
static |
Referenced by CheckStl::globalLockGuardError().
|
static |
Referenced by CheckStl::missingComparisonError().