Cppcheck
|
Check input output operations. More...
#include <checkio.h>
Classes | |
class | ArgumentInfo |
Public Member Functions | |
CheckIO () | |
This constructor is used when registering CheckIO. 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 | |
CheckIO (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 on the normal token list. More... | |
void | checkCoutCerrMisusage () |
Check for missusage of std::cout More... | |
void | checkFileUsage () |
Check usage of files More... | |
void | invalidScanf () |
scanf can crash if width specifiers are not used More... | |
void | checkWrongPrintfScanfArguments () |
Checks type and number of arguments given to functions like printf or scanf More... | |
void | checkFormatString (const Token *const tok, const Token *const formatStringTok, const Token *argListTok, const bool scan, const bool scanf_s) |
void | coutCerrMisusageError (const Token *tok, const std::string &streamName) |
void | fflushOnInputStreamError (const Token *tok, const std::string &varname) |
void | ioWithoutPositioningError (const Token *tok) |
void | readWriteOnlyFileError (const Token *tok) |
void | writeReadOnlyFileError (const Token *tok) |
void | useClosedFileError (const Token *tok) |
void | seekOnAppendedFileError (const Token *tok) |
void | incompatibleFileOpenError (const Token *tok, const std::string &filename) |
void | invalidScanfError (const Token *tok) |
void | wrongPrintfScanfArgumentsError (const Token *tok, const std::string &functionName, nonneg int numFormat, nonneg int numFunction) |
void | wrongPrintfScanfPosixParameterPositionError (const Token *tok, const std::string &functionName, nonneg int index, nonneg int numFunction) |
void | invalidScanfArgTypeError_s (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo) |
void | invalidScanfArgTypeError_int (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo, bool isUnsigned) |
void | invalidScanfArgTypeError_float (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_s (const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_n (const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_p (const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_uint (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_sint (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo) |
void | invalidPrintfArgTypeError_float (const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo) |
void | invalidLengthModifierError (const Token *tok, nonneg int numFormat, const std::string &modifier) |
void | invalidScanfFormatWidthError (const Token *tok, nonneg int numFormat, int width, const Variable *var, const std::string &specifier) |
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 void | argumentType (std::ostream &os, const ArgumentInfo *argInfo) |
static Severity | getSeverity (const ArgumentInfo *argInfo) |
static std::string | myName () |
Friends | |
class | TestIO |
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 {} |
|
inline |
|
inlineprivate |
|
staticprivate |
Definition at line 1945 of file checkio.cpp.
References CheckIO::ArgumentInfo::address, CheckIO::ArgumentInfo::element, Token::eString, Variable::isArray(), Token::isLong(), Token::isUnsigned(), Token::Match(), Token::next(), Token::originalName(), Token::str(), Token::strAt(), Token::stringify(), Token::tokAt(), Token::tokType(), CheckIO::ArgumentInfo::typeToken, and CheckIO::ArgumentInfo::variableInfo.
Referenced by invalidPrintfArgTypeError_float(), invalidPrintfArgTypeError_n(), invalidPrintfArgTypeError_p(), invalidPrintfArgTypeError_s(), invalidPrintfArgTypeError_sint(), invalidPrintfArgTypeError_uint(), invalidScanfArgTypeError_float(), invalidScanfArgTypeError_int(), and invalidScanfArgTypeError_s().
|
private |
Check for missusage of std::cout
Definition at line 66 of file checkio.cpp.
References Token::astOperand2(), Token::astParent(), Scope::bodyEnd, Scope::bodyStart, coutCerrMisusageError(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Tokenizer::isC(), Check::logChecker(), Token::Match(), Check::mTokenizer, and Token::next().
Referenced by runChecks().
|
private |
Check usage of files
Definition at line 127 of file checkio.cpp.
References Scope::bodyEnd, Scope::bodyStart, CLOSED, Token::eString, fflushOnInputStreamError(), Scope::function, Scope::functionOf, SymbolDatabase::functionScopes, getMode(), Tokenizer::getSymbolDatabase(), SymbolDatabase::getVariableFromVarId(), incompatibleFileOpenError(), indent(), ioWithoutPositioningError(), Scope::isClassOrStruct(), SimpleEnableGroup< T >::isEnabled(), Library::isFunctionConst(), Variable::isGlobal(), Variable::isLocal(), Library::isnoreturn(), Variable::isStatic(), Function::isStatic(), isUnevaluated(), Platform::isWindows(), Settings::library, Token::linkAt(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), Settings::platform, portability, Token::previous(), READ_MODE, readWriteOnlyFileError(), RW_MODE, seekOnAppendedFileError(), Settings::severity, Token::simpleMatch(), Token::str(), Token::strAt(), Token::strValue(), Token::tokAt(), Token::tokType(), UNKNOWN_OM, useClosedFileError(), SymbolDatabase::variableList(), Token::varId(), warning, WRITE_MODE, and writeReadOnlyFileError().
Referenced by runChecks().
|
private |
Definition at line 603 of file checkio.cpp.
References Variable::dimension(), Variable::dimensions(), done, CheckIO::ArgumentInfo::element, Token::eString, FALLTHROUGH, invalidLengthModifierError(), invalidPrintfArgTypeError_float(), invalidPrintfArgTypeError_n(), invalidPrintfArgTypeError_p(), invalidPrintfArgTypeError_s(), invalidPrintfArgTypeError_sint(), invalidPrintfArgTypeError_uint(), invalidScanfArgTypeError_float(), invalidScanfArgTypeError_int(), invalidScanfArgTypeError_s(), invalidScanfFormatWidthError(), Variable::isArray(), CheckIO::ArgumentInfo::isArrayOrPointer(), Tokenizer::isCPP(), SimpleEnableGroup< T >::isEnabled(), CheckIO::ArgumentInfo::isKnownType(), CheckIO::ArgumentInfo::isLibraryType(), Token::isLong(), Token::isStandardType(), Token::isUnsigned(), Platform::isWindows(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::nextArgument(), Token::originalName(), Settings::platform, Settings::severity, Token::str(), Token::strAt(), Token::tokType(), typesMatch(), CheckIO::ArgumentInfo::typeToken, CheckIO::ArgumentInfo::variableInfo, warning, wrongPrintfScanfArgumentsError(), and wrongPrintfScanfPosixParameterPositionError().
Referenced by checkWrongPrintfScanfArguments().
|
private |
Checks type and number of arguments given to functions like printf or scanf
Definition at line 531 of file checkio.cpp.
References Scope::bodyEnd, Scope::bodyStart, checkFormatString(), findFormat(), Library::formatstr_argno(), Library::formatstr_function(), Library::formatstr_scan(), Library::formatstr_secure(), SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), Platform::isWindows(), Settings::library, Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Settings::platform, and Token::simpleMatch().
Referenced by runChecks().
|
inlineoverrideprivatevirtual |
|
private |
Definition at line 88 of file checkio.cpp.
References CWE398, error, normal, and Check::reportError().
Referenced by checkCoutCerrMisusage(), and getErrorMessages().
|
private |
Definition at line 366 of file checkio.cpp.
References CWE398, normal, portability, and Check::reportError().
Referenced by checkFileUsage(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
get error messages
Implements Check.
Definition at line 137 of file checkio.h.
References coutCerrMisusageError(), fflushOnInputStreamError(), incompatibleFileOpenError(), invalidLengthModifierError(), invalidPrintfArgTypeError_float(), invalidPrintfArgTypeError_n(), invalidPrintfArgTypeError_p(), invalidPrintfArgTypeError_s(), invalidPrintfArgTypeError_sint(), invalidPrintfArgTypeError_uint(), invalidScanfArgTypeError_float(), invalidScanfArgTypeError_int(), invalidScanfArgTypeError_s(), invalidScanfError(), invalidScanfFormatWidthError(), ioWithoutPositioningError(), readWriteOnlyFileError(), seekOnAppendedFileError(), useClosedFileError(), writeReadOnlyFileError(), wrongPrintfScanfArgumentsError(), and wrongPrintfScanfPosixParameterPositionError().
|
staticprivate |
Definition at line 1940 of file checkio.cpp.
References Token::originalName(), portability, CheckIO::ArgumentInfo::typeToken, and warning.
Referenced by invalidPrintfArgTypeError_float(), invalidPrintfArgTypeError_n(), invalidPrintfArgTypeError_p(), invalidPrintfArgTypeError_s(), invalidPrintfArgTypeError_sint(), invalidPrintfArgTypeError_uint(), invalidScanfArgTypeError_float(), invalidScanfArgTypeError_int(), and invalidScanfArgTypeError_s().
|
private |
Definition at line 402 of file checkio.cpp.
References CWE664, normal, Check::reportError(), and warning.
Referenced by checkFileUsage(), and getErrorMessages().
|
private |
Definition at line 1995 of file checkio.cpp.
References CWE704, SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and warning.
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1925 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1837 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1848 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1826 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1912 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, printfFormatType(), Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1898 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, printfFormatType(), Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
scanf can crash if width specifiers are not used
Definition at line 412 of file checkio.cpp.
References Scope::bodyEnd, Scope::bodyStart, Token::eString, SymbolDatabase::functionScopes, Tokenizer::getSymbolDatabase(), invalidScanfError(), SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::logChecker(), Token::Match(), Check::mSettings, Check::mTokenizer, Token::next(), Token::nextArgument(), Settings::severity, Token::str(), Token::tokAt(), Token::tokType(), and warning.
Referenced by runChecks().
|
private |
Definition at line 1807 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1762 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1746 of file checkio.cpp.
References argumentType(), CWE686, getSeverity(), SimpleEnableGroup< T >::isEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and Token::str().
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 459 of file checkio.cpp.
References CWE119, normal, Check::reportError(), Token::str(), and warning.
Referenced by getErrorMessages(), and invalidScanf().
|
private |
Definition at line 2004 of file checkio.cpp.
References Settings::certainty, CWE687, Variable::dimension(), error, inconclusive, SimpleEnableGroup< T >::isEnabled(), Check::mSettings, Variable::name(), normal, Check::reportError(), Settings::severity, and warning.
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 372 of file checkio.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by checkFileUsage(), and getErrorMessages().
|
inlinestaticprivate |
|
private |
Definition at line 378 of file checkio.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by checkFileUsage(), and getErrorMessages().
|
inlineoverrideprivatevirtual |
Run checks on the normal token list.
Implements Check.
Definition at line 55 of file checkio.h.
References checkCoutCerrMisusage(), checkFileUsage(), checkWrongPrintfScanfArguments(), Tokenizer::getSettings(), and invalidScanf().
|
private |
Definition at line 396 of file checkio.cpp.
References CWE398, normal, Check::reportError(), and warning.
Referenced by checkFileUsage(), and getErrorMessages().
|
private |
Definition at line 390 of file checkio.cpp.
References CWE910, error, normal, and Check::reportError().
Referenced by checkFileUsage(), and getErrorMessages().
|
private |
Definition at line 384 of file checkio.cpp.
References CWE664, error, normal, and Check::reportError().
Referenced by checkFileUsage(), and getErrorMessages().
|
private |
Definition at line 1709 of file checkio.cpp.
References CWE685, error, SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, Token::str(), and warning.
Referenced by checkFormatString(), and getErrorMessages().
|
private |
Definition at line 1731 of file checkio.cpp.
References CWE685, SimpleEnableGroup< T >::isEnabled(), Settings::isPremiumEnabled(), Check::mSettings, normal, Check::reportError(), Settings::severity, and warning.
Referenced by checkFormatString(), and getErrorMessages().