Cppcheck
|
Various small checks. More...
#include <checktype.h>
Public Member Functions | |
CheckType () | |
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 Member Functions | |
CheckType (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 | checkTooBigBitwiseShift () |
Check for bitwise shift with too big right operand More... | |
void | checkIntegerOverflow () |
Check for integer overflow More... | |
void | checkSignConversion () |
Check for dangerous sign conversion More... | |
void | checkLongCast () |
Check for implicit long cast of int result More... | |
void | checkFloatToIntegerOverflow () |
Check for float to integer overflow More... | |
void | checkFloatToIntegerOverflow (const Token *tok, const ValueType *vtint, const ValueType *vtfloat, const std::list< ValueFlow::Value > &floatValues) |
void | tooBigBitwiseShiftError (const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits) |
void | tooBigSignedBitwiseShiftError (const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits) |
void | integerOverflowError (const Token *tok, const ValueFlow::Value &value) |
void | signConversionError (const Token *tok, const ValueFlow::Value *negativeValue, const bool constvalue) |
void | longCastAssignError (const Token *tok, const ValueType *src=nullptr, const ValueType *tgt=nullptr) |
void | longCastReturnError (const Token *tok, const ValueType *src=nullptr, const ValueType *tgt=nullptr) |
void | floatToIntegerOverflowError (const Token *tok, const ValueFlow::Value &value) |
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 {} |
Various small checks.
Definition at line 44 of file checktype.h.
|
inline |
This constructor is used when registering the CheckClass.
Definition at line 47 of file checktype.h.
|
inlineprivate |
This constructor is used when running checks.
Definition at line 51 of file checktype.h.
|
private |
Check for float to integer overflow
Definition at line 431 of file checktype.cpp.
References Scope::function, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Scope::nestedIn, Token::next(), ValueType::parseDecl(), Function::retDef, Tokenizer::tokens(), and Scope::type.
Referenced by runChecks().
|
private |
Definition at line 465 of file checktype.cpp.
References Platform::char_bit, ValueFlow::Value::FLOAT, floatToIntegerOverflowError(), Platform::int_bit, Settings::isEnabled(), ValueType::isFloat(), ValueType::isIntegral(), Platform::long_bit, Platform::long_long_bit, Check::mSettings, Settings::platform, Platform::short_bit, Platform::type, and ValueType::type.
|
private |
Check for integer overflow
Definition at line 167 of file checktype.cpp.
References MathLib::bigint_bits, Platform::int_bit, integerOverflowError(), ValueFlow::Value::intvalue, Settings::isEnabled(), ValueType::isIntegral(), Check::logChecker(), Platform::long_bit, Platform::long_long_bit, Check::mSettings, Check::mTokenizer, Token::next(), Settings::platform, ValueType::sign, Tokenizer::tokens(), Platform::type, and ValueType::type.
Referenced by runChecks().
|
private |
Check for implicit long cast of int result
Definition at line 326 of file checktype.cpp.
References Token::astOperand1(), Scope::bodyEnd, Scope::bodyStart, checkTypeCombination(), Scope::classDef, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), ValueFlow::Value::intvalue, SimpleEnableGroup< T >::isEnabled(), Platform::isIntValue(), Settings::isPremiumEnabled(), Check::logChecker(), longCastAssignError(), longCastReturnError(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), ValueType::originalTypeName, Settings::platform, ValueType::pointer, Settings::severity, style, Tokenizer::tokens(), and Token::valueType().
Referenced by runChecks().
|
private |
Check for dangerous sign conversion
Definition at line 241 of file checktype.cpp.
References Token::astOperand1(), ValueFlow::findValue(), SimpleEnableGroup< T >::isEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::severity, signConversionError(), Tokenizer::tokens(), and warning.
Referenced by runChecks().
|
private |
Check for bitwise shift with too big right operand
Definition at line 61 of file checktype.cpp.
References Platform::int_bit, Settings::isEnabled(), ValueType::isIntegral(), Check::logChecker(), Platform::long_bit, Platform::long_long_bit, Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::platform, ValueType::pointer, ValueType::sign, Token::simpleMatch(), Tokenizer::tokens(), tooBigBitwiseShiftError(), tooBigSignedBitwiseShiftError(), Platform::type, and ValueType::type.
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
get information about this class, used to generate documentation
Implements Check.
Definition at line 108 of file checktype.h.
|
private |
Definition at line 502 of file checktype.cpp.
References CWE190, error, ValueFlow::Value::errorSeverity(), ValueFlow::Value::floatValue, Check::getErrorPath(), inconclusive, ValueFlow::Value::isInconclusive(), normal, Check::reportError(), and warning.
Referenced by checkFloatToIntegerOverflow(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 90 of file checktype.h.
References ValueFlow::Value::FLOAT, floatToIntegerOverflowError(), ValueFlow::Value::floatValue, integerOverflowError(), longCastAssignError(), longCastReturnError(), signConversionError(), tooBigBitwiseShiftError(), tooBigSignedBitwiseShiftError(), and ValueFlow::Value::valueType.
|
private |
Definition at line 215 of file checktype.cpp.
References ValueFlow::Value::condition, CWE190, ValueFlow::eitherTheConditionIsRedundant(), error, ValueFlow::Value::errorSeverity(), Token::expressionString(), Check::getErrorPath(), Check::getMessageId(), inconclusive, ValueFlow::Value::isInconclusive(), normal, Check::reportError(), ValueFlow::Value::safe, and warning.
Referenced by checkIntegerOverflow(), and getErrorMessages().
|
private |
Definition at line 401 of file checktype.cpp.
References CWE197, makeBaseTypeString(), normal, Check::reportError(), ValueType::str(), and style.
Referenced by checkLongCast(), and getErrorMessages().
|
private |
Definition at line 414 of file checktype.cpp.
References CWE197, makeBaseTypeString(), normal, Check::reportError(), ValueType::str(), and style.
Referenced by checkLongCast(), and getErrorMessages().
|
inlinestaticprivate |
Definition at line 104 of file checktype.h.
|
inlineoverrideprivatevirtual |
Run checks against the normal token list.
Implements Check.
Definition at line 55 of file checktype.h.
References checkFloatToIntegerOverflow(), checkIntegerOverflow(), checkLongCast(), checkSignConversion(), checkTooBigBitwiseShift(), and Tokenizer::getSettings().
|
private |
Definition at line 273 of file checktype.cpp.
References CWE195, Token::expressionString(), Check::getErrorPath(), Check::getMessageId(), inconclusive, ValueFlow::Value::isInconclusive(), Token::isName(), normal, Check::reportError(), and warning.
Referenced by checkSignConversion(), and getErrorMessages().
|
private |
Definition at line 113 of file checktype.cpp.
References ValueFlow::Value::condition, CWE758, error, ValueFlow::Value::errorSeverity(), Check::getErrorPath(), inconclusive, ValueFlow::Value::intvalue, ValueFlow::Value::isInconclusive(), Token::linenr(), normal, Check::reportError(), and warning.
Referenced by checkTooBigBitwiseShift(), and getErrorMessages().
|
private |
Definition at line 132 of file checktype.cpp.
References ValueFlow::Value::condition, Standards::cpp, Standards::CPP14, CWE758, error, ValueFlow::Value::errorSeverity(), Check::getErrorPath(), inconclusive, ValueFlow::Value::intvalue, Token::isCpp(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), ValueFlow::Value::isInconclusive(), Token::linenr(), Check::mSettings, Check::mTokenizer, normal, portability, Check::reportError(), Settings::severity, Settings::standards, and warning.
Referenced by checkTooBigBitwiseShift(), and getErrorMessages().