Cppcheck
|
Check for bad function usage. More...
#include <checkfunctions.h>
Public Member Functions | |
CheckFunctions () | |
This constructor is used when registering the CheckFunctions. 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 Member Functions | |
CheckFunctions (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 against the normal token list. More... | |
void | checkProhibitedFunctions () |
Check for functions that should not be used. More... | |
void | invalidFunctionUsage () |
Invalid function usage (invalid input value / overlapping data) More... | |
void | checkIgnoredReturnValue () |
Check for ignored return values. More... | |
void | checkMathFunctions () |
Check for parameters given to math function that do not make sense More... | |
void | memsetZeroBytes () |
Check for filling zero bytes with memset() More... | |
void | memsetInvalid2ndParam () |
Check for invalid 2nd parameter of memset() More... | |
void | returnLocalStdMove () |
Check for copy elision by RVO|NRVO More... | |
void | useStandardLibrary () |
void | checkLibraryMatchFunctions () |
–check-library: warn for unconfigured function calls More... | |
void | checkMissingReturn () |
Check for missing "return" More... | |
void | invalidFunctionArgError (const Token *tok, const std::string &functionName, int argnr, const ValueFlow::Value *invalidValue, const std::string &validstr) |
void | invalidFunctionArgBoolError (const Token *tok, const std::string &functionName, int argnr) |
void | invalidFunctionArgStrError (const Token *tok, const std::string &functionName, nonneg int argnr) |
void | ignoredReturnValueError (const Token *tok, const std::string &function) |
void | ignoredReturnErrorCode (const Token *tok, const std::string &function) |
void | mathfunctionCallWarning (const Token *tok, const nonneg int numParam=1) |
void | mathfunctionCallWarning (const Token *tok, const std::string &oldexp, const std::string &newexp) |
void | memsetZeroBytesError (const Token *tok) |
void | memsetFloatError (const Token *tok, const std::string &var_value) |
void | memsetValueOutOfRangeError (const Token *tok, const std::string &value) |
void | missingReturnError (const Token *tok) |
void | copyElisionError (const Token *tok) |
void | useStandardLibraryError (const Token *tok, const std::string &expected) |
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 for bad function usage.
Definition at line 50 of file checkfunctions.h.
|
inline |
This constructor is used when registering the CheckFunctions.
Definition at line 53 of file checkfunctions.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 57 of file checkfunctions.h.
|
private |
Check for ignored return values.
Definition at line 243 of file checkfunctions.cpp.
References Token::astParent(), Scope::bodyEnd, Scope::bodyStart, Library::DEFAULT, Library::ERROR_CODE, SymbolDatabase::functionScopes, Library::getAllocFuncInfo(), Tokenizer::getSymbolDatabase(), Library::getUseRetValType(), ignoredReturnErrorCode(), ignoredReturnValueError(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, style, and warning.
Referenced by runChecks().
|
private |
–check-library: warn for unconfigured function calls
Definition at line 610 of file checkfunctions.cpp.
References astContainerAction(), astContainerYield(), Token::astParent(), Settings::checkLibrary, Library::def, Library::detectContainerOrIterator(), Library::functions, Library::getFunctionName(), Library::getTypeCheck(), information, Token::isKeyword(), Library::isNotLibraryFunction(), Settings::library, Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Library::Container::NO_ACTION, Library::Container::NO_YIELD, Library::podtype(), Check::reportError(), Token::simpleMatch(), Token::tokAt(), and Tokenizer::tokens().
Referenced by runChecks().
|
private |
Check for parameters given to math function that do not make sense
Definition at line 424 of file checkfunctions.cpp.
References Token::astOperand1(), Token::astOperand2(), Scope::bodyEnd, Scope::bodyStart, Standards::c, Standards::C89, Standards::cpp, Standards::CPP03, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Tokenizer::isC(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), MathLib::isFloat(), MathLib::isInt(), MathLib::isNegative(), MathLib::isNullValue(), Tokenizer::isOneNumber(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), mathfunctionCallWarning(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), Settings::severity, Token::simpleMatch(), Settings::standards, Token::str(), style, MathLib::toBigNumber(), MathLib::toDoubleNumber(), Token::tokAt(), and warning.
Referenced by runChecks().
|
private |
Check for missing "return"
Definition at line 310 of file checkfunctions.cpp.
References Scope::bodyEnd, Standards::c, Standards::C99, checkMissingReturnScope(), Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Tokenizer::isC(), Settings::library, Check::logChecker(), Token::Match(), missingReturnError(), Check::mSettings, Check::mTokenizer, Function::returnsVoid(), and Settings::standards.
Referenced by runChecks().
|
private |
Check for functions that should not be used.
Definition at line 57 of file checkfunctions.cpp.
References Scope::bodyEnd, Scope::bodyStart, Standards::c, Standards::C89, Standards::C99, Standards::cpp, Standards::CPP11, CWE477, Settings::daca, Scope::eGlobal, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Library::getWarnInfo(), Tokenizer::isC(), SimpleEnableGroup< T >::isEnabled(), Settings::library, Check::logChecker(), Token::Match(), Library::WarnInfo::message, Check::mSettings, Check::mTokenizer, Token::next(), normal, Check::reportError(), Library::WarnInfo::severity, Settings::severity, Token::simpleMatch(), Library::WarnInfo::standards, Settings::standards, and warning.
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 154 of file checkfunctions.h.
|
private |
Definition at line 712 of file checkfunctions.cpp.
References performance, and Check::reportError().
Referenced by getErrorMessages(), and returnLocalStdMove().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 129 of file checkfunctions.h.
References copyElisionError(), Library::functionwarn, ignoredReturnValueError(), invalidFunctionArgBoolError(), invalidFunctionArgError(), invalidFunctionArgStrError(), Settings::library, mathfunctionCallWarning(), memsetFloatError(), memsetValueOutOfRangeError(), memsetZeroBytesError(), missingReturnError(), Check::reportError(), style, and useStandardLibraryError().
|
private |
Definition at line 299 of file checkfunctions.cpp.
References CWE252, normal, Check::reportError(), and style.
Referenced by checkIgnoredReturnValue().
|
private |
Definition at line 293 of file checkfunctions.cpp.
References CWE252, normal, Check::reportError(), and warning.
Referenced by checkIgnoredReturnValue(), and getErrorMessages().
|
private |
Definition at line 224 of file checkfunctions.cpp.
References CWE628, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and invalidFunctionUsage().
|
private |
Definition at line 195 of file checkfunctions.cpp.
References ValueFlow::Value::condition, CWE628, ValueFlow::eitherTheConditionIsRedundant(), error, ValueFlow::Value::errorSeverity(), ValueFlow::Value::floatValue, Check::getErrorPath(), inconclusive, ValueFlow::Value::intvalue, ValueFlow::Value::isInconclusive(), ValueFlow::Value::isIntValue(), ValueFlow::Value::isKnown(), normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and invalidFunctionUsage().
|
private |
Definition at line 232 of file checkfunctions.cpp.
References CWE628, error, normal, and Check::reportError().
Referenced by getErrorMessages(), and invalidFunctionUsage().
|
private |
Invalid function usage (invalid input value / overlapping data)
Check that given function parameters are valid according to the standard
Definition at line 104 of file checkfunctions.cpp.
References astIsBool(), Token::astOperand1(), Scope::bodyEnd, Scope::bodyStart, Variable::declEndToken(), SymbolDatabase::functionScopes, getArguments(), Token::getInvalidValue(), Token::getKnownIntValue(), Token::getStrArraySize(), Tokenizer::getSymbolDatabase(), Token::getValue(), Token::getValueTokenMinStrSize(), Token::hasKnownIntValue(), Token::hasKnownValue(), invalidFunctionArgBoolError(), invalidFunctionArgError(), invalidFunctionArgStrError(), Library::isargstrz(), Variable::isArray(), Library::isboolargbad(), Variable::isConst(), Variable::isGlobal(), Library::isIntArgValid(), Variable::isLocal(), isVariablesChanged(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::simpleMatch(), Token::str(), Token::tokAt(), ValueType::type, Library::validarg(), Token::valueType(), and Token::variable().
Referenced by runChecks().
|
private |
Definition at line 485 of file checkfunctions.cpp.
References CWE758, normal, Check::reportError(), Token::str(), Token::strAt(), and warning.
Referenced by checkMathFunctions(), and getErrorMessages().
|
private |
Definition at line 496 of file checkfunctions.cpp.
References CWE758, normal, Check::reportError(), and style.
|
private |
Definition at line 590 of file checkfunctions.cpp.
References CWE688, normal, portability, and Check::reportError().
Referenced by getErrorMessages(), and memsetInvalid2ndParam().
|
private |
Check for invalid 2nd parameter of memset()
Definition at line 542 of file checkfunctions.cpp.
References astIsFloat(), Scope::bodyEnd, Scope::bodyStart, Token::expressionString(), SymbolDatabase::functionScopes, getArguments(), Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), MathLib::isNullValue(), Token::isNumber(), Check::logChecker(), Token::Match(), memsetFloatError(), memsetValueOutOfRangeError(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::platform, portability, Settings::severity, Platform::signedCharMin(), Token::simpleMatch(), Token::str(), MathLib::toBigNumber(), Platform::unsignedCharMax(), and warning.
Referenced by runChecks().
|
private |
Definition at line 599 of file checkfunctions.cpp.
References CWE686, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and memsetInvalid2ndParam().
|
private |
Check for filling zero bytes with memset()
Definition at line 504 of file checkfunctions.cpp.
References Scope::bodyEnd, Scope::bodyStart, SymbolDatabase::functionScopes, getArguments(), Tokenizer::getSymbolDatabase(), SimpleEnableGroup< T >::isEnabled(), MathLib::isNullValue(), Check::logChecker(), Token::Match(), memsetZeroBytesError(), Check::mSettings, Check::mTokenizer, Token::next(), numberOfArguments(), Settings::severity, Token::str(), warning, and WRONG_DATA.
Referenced by runChecks().
|
private |
Definition at line 533 of file checkfunctions.cpp.
References CWE687, normal, Check::reportError(), and warning.
Referenced by getErrorMessages(), and memsetZeroBytes().
|
private |
Definition at line 416 of file checkfunctions.cpp.
References CWE758, error, normal, and Check::reportError().
Referenced by checkMissingReturn(), and getErrorMessages().
|
inlinestaticprivate |
Definition at line 150 of file checkfunctions.h.
|
private |
Check for copy elision by RVO|NRVO
Definition at line 682 of file checkfunctions.cpp.
References Token::astOperand2(), copyElisionError(), Standards::cpp, Standards::CPP11, Function::findReturns(), Scope::function, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Token::isCast(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, None, performance, ValueType::reference, Function::returnsReference(), Settings::severity, Token::simpleMatch(), Settings::standards, Token::valueType(), and Token::variable().
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
Run checks against the normal token list.
Implements Check.
Definition at line 61 of file checkfunctions.h.
References checkIgnoredReturnValue(), checkLibraryMatchFunctions(), checkMathFunctions(), checkMissingReturn(), checkProhibitedFunctions(), Tokenizer::getSettings(), invalidFunctionUsage(), memsetInvalid2ndParam(), memsetZeroBytes(), returnLocalStdMove(), and useStandardLibrary().
|
private |
Definition at line 721 of file checkfunctions.cpp.
References Token::astOperand1(), Token::astOperand2(), getCondTok(), getInitTok(), Token::getKnownIntValue(), getStepTok(), Tokenizer::getSymbolDatabase(), Token::hasKnownIntValue(), Token::isBinaryOp(), Token::isComparisonOp(), isConstExpression(), Token::isCpp(), SimpleEnableGroup< T >::isEnabled(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), SymbolDatabase::scopeList, Settings::severity, Token::str(), style, useStandardLibraryError(), and Token::varId().
Referenced by runChecks().
|
private |
Definition at line 825 of file checkfunctions.cpp.
References Check::reportError(), and style.
Referenced by getErrorMessages(), and useStandardLibrary().