Cppcheck
Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Friends | List of all members
CheckIO Class Reference

Check input output operations. More...

#include <checkio.h>

Inheritance diagram for CheckIO:
Check

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
 
Checkoperator= (const Check &)=delete
 
const std::string & name () const
 class name, used to generate documentation More...
 
virtual FileInfogetFileInfo (const Tokenizer &, const Settings &) const
 
virtual FileInfoloadFileInfoFromXml (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 {}
 

Detailed Description

Check input output operations.

Definition at line 42 of file checkio.h.

Constructor & Destructor Documentation

◆ CheckIO() [1/2]

CheckIO::CheckIO ( )
inline

This constructor is used when registering CheckIO.

Definition at line 47 of file checkio.h.

◆ CheckIO() [2/2]

CheckIO::CheckIO ( const Tokenizer tokenizer,
const Settings settings,
ErrorLogger errorLogger 
)
inlineprivate

This constructor is used when running checks.

Definition at line 51 of file checkio.h.

Member Function Documentation

◆ argumentType()

void CheckIO::argumentType ( std::ostream &  os,
const ArgumentInfo argInfo 
)
staticprivate

◆ checkCoutCerrMisusage()

void CheckIO::checkCoutCerrMisusage ( )
private

◆ checkFileUsage()

void CheckIO::checkFileUsage ( )
private

◆ checkFormatString()

void CheckIO::checkFormatString ( const Token *const  tok,
const Token *const  formatStringTok,
const Token argListTok,
const bool  scan,
const bool  scanf_s 
)
private

◆ checkWrongPrintfScanfArguments()

void CheckIO::checkWrongPrintfScanfArguments ( )
private

◆ classInfo()

std::string CheckIO::classInfo ( ) const
inlineoverrideprivatevirtual

get information about this class, used to generate documentation

Implements Check.

Definition at line 168 of file checkio.h.

◆ coutCerrMisusageError()

void CheckIO::coutCerrMisusageError ( const Token tok,
const std::string &  streamName 
)
private

Definition at line 88 of file checkio.cpp.

References CWE398, error, normal, and Check::reportError().

Referenced by checkCoutCerrMisusage(), and getErrorMessages().

◆ fflushOnInputStreamError()

void CheckIO::fflushOnInputStreamError ( const Token tok,
const std::string &  varname 
)
private

Definition at line 366 of file checkio.cpp.

References CWE398, normal, portability, and Check::reportError().

Referenced by checkFileUsage(), and getErrorMessages().

◆ getErrorMessages()

void CheckIO::getErrorMessages ( ErrorLogger errorLogger,
const Settings settings 
) const
inlineoverrideprivatevirtual

◆ getSeverity()

Severity CheckIO::getSeverity ( const ArgumentInfo argInfo)
staticprivate

◆ incompatibleFileOpenError()

void CheckIO::incompatibleFileOpenError ( const Token tok,
const std::string &  filename 
)
private

Definition at line 402 of file checkio.cpp.

References CWE664, normal, Check::reportError(), and warning.

Referenced by checkFileUsage(), and getErrorMessages().

◆ invalidLengthModifierError()

void CheckIO::invalidLengthModifierError ( const Token tok,
nonneg int  numFormat,
const std::string &  modifier 
)
private

◆ invalidPrintfArgTypeError_float()

void CheckIO::invalidPrintfArgTypeError_float ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo 
)
private

◆ invalidPrintfArgTypeError_n()

void CheckIO::invalidPrintfArgTypeError_n ( const Token tok,
nonneg int  numFormat,
const ArgumentInfo argInfo 
)
private

◆ invalidPrintfArgTypeError_p()

void CheckIO::invalidPrintfArgTypeError_p ( const Token tok,
nonneg int  numFormat,
const ArgumentInfo argInfo 
)
private

◆ invalidPrintfArgTypeError_s()

void CheckIO::invalidPrintfArgTypeError_s ( const Token tok,
nonneg int  numFormat,
const ArgumentInfo argInfo 
)
private

◆ invalidPrintfArgTypeError_sint()

void CheckIO::invalidPrintfArgTypeError_sint ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo 
)
private

◆ invalidPrintfArgTypeError_uint()

void CheckIO::invalidPrintfArgTypeError_uint ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo 
)
private

◆ invalidScanf()

void CheckIO::invalidScanf ( )
private

◆ invalidScanfArgTypeError_float()

void CheckIO::invalidScanfArgTypeError_float ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo 
)
private

◆ invalidScanfArgTypeError_int()

void CheckIO::invalidScanfArgTypeError_int ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo,
bool  isUnsigned 
)
private

◆ invalidScanfArgTypeError_s()

void CheckIO::invalidScanfArgTypeError_s ( const Token tok,
nonneg int  numFormat,
const std::string &  specifier,
const ArgumentInfo argInfo 
)
private

◆ invalidScanfError()

void CheckIO::invalidScanfError ( const Token tok)
private

Definition at line 459 of file checkio.cpp.

References CWE119, normal, Check::reportError(), Token::str(), and warning.

Referenced by getErrorMessages(), and invalidScanf().

◆ invalidScanfFormatWidthError()

void CheckIO::invalidScanfFormatWidthError ( const Token tok,
nonneg int  numFormat,
int  width,
const Variable var,
const std::string &  specifier 
)
private

◆ ioWithoutPositioningError()

void CheckIO::ioWithoutPositioningError ( const Token tok)
private

Definition at line 372 of file checkio.cpp.

References CWE664, error, normal, and Check::reportError().

Referenced by checkFileUsage(), and getErrorMessages().

◆ myName()

static std::string CheckIO::myName ( )
inlinestaticprivate

Definition at line 164 of file checkio.h.

◆ readWriteOnlyFileError()

void CheckIO::readWriteOnlyFileError ( const Token tok)
private

Definition at line 378 of file checkio.cpp.

References CWE664, error, normal, and Check::reportError().

Referenced by checkFileUsage(), and getErrorMessages().

◆ runChecks()

void CheckIO::runChecks ( const Tokenizer tokenizer,
ErrorLogger errorLogger 
)
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().

◆ seekOnAppendedFileError()

void CheckIO::seekOnAppendedFileError ( const Token tok)
private

Definition at line 396 of file checkio.cpp.

References CWE398, normal, Check::reportError(), and warning.

Referenced by checkFileUsage(), and getErrorMessages().

◆ useClosedFileError()

void CheckIO::useClosedFileError ( const Token tok)
private

Definition at line 390 of file checkio.cpp.

References CWE910, error, normal, and Check::reportError().

Referenced by checkFileUsage(), and getErrorMessages().

◆ writeReadOnlyFileError()

void CheckIO::writeReadOnlyFileError ( const Token tok)
private

Definition at line 384 of file checkio.cpp.

References CWE664, error, normal, and Check::reportError().

Referenced by checkFileUsage(), and getErrorMessages().

◆ wrongPrintfScanfArgumentsError()

void CheckIO::wrongPrintfScanfArgumentsError ( const Token tok,
const std::string &  functionName,
nonneg int  numFormat,
nonneg int  numFunction 
)
private

◆ wrongPrintfScanfPosixParameterPositionError()

void CheckIO::wrongPrintfScanfPosixParameterPositionError ( const Token tok,
const std::string &  functionName,
nonneg int  index,
nonneg int  numFunction 
)
private

Friends And Related Function Documentation

◆ TestIO

friend class TestIO
friend

Definition at line 43 of file checkio.h.


The documentation for this class was generated from the following files: