52         : 
Check(myName(), tokenizer, settings, errorLogger) {}
 
   65     void checkCoutCerrMisusage();
 
   68     void checkFileUsage();
 
   74     void checkWrongPrintfScanfArguments();
 
   84         bool isArrayOrPointer() 
const;
 
   85         bool isComplexType() 
const;
 
   86         bool isKnownType() 
const;
 
   87         bool isStdVectorOrString();
 
   88         bool isStdContainer(
const Token *tok);
 
   89         bool isLibraryType(
const Settings &settings) 
const;
 
  101     void checkFormatString(
const Token * 
const tok,
 
  102                            const Token * 
const formatStringTok,
 
  103                            const Token *       argListTok,
 
  108     void coutCerrMisusageError(
const Token* tok, 
const std::string& streamName);
 
  109     void fflushOnInputStreamError(
const Token *tok, 
const std::string &varname);
 
  110     void ioWithoutPositioningError(
const Token *tok);
 
  111     void readWriteOnlyFileError(
const Token *tok);
 
  112     void writeReadOnlyFileError(
const Token *tok);
 
  113     void useClosedFileError(
const Token *tok);
 
  114     void seekOnAppendedFileError(
const Token *tok);
 
  115     void incompatibleFileOpenError(
const Token *tok, 
const std::string &filename);
 
  116     void invalidScanfError(
const Token *tok);
 
  117     void wrongPrintfScanfArgumentsError(
const Token* tok,
 
  118                                         const std::string &functionName,
 
  121     void wrongPrintfScanfPosixParameterPositionError(
const Token* tok, 
const std::string& functionName,
 
  123     void invalidScanfArgTypeError_s(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo);
 
  124     void invalidScanfArgTypeError_int(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo, 
bool isUnsigned);
 
  125     void invalidScanfArgTypeError_float(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo);
 
  126     void invalidPrintfArgTypeError_s(
const Token* tok, 
nonneg int numFormat, 
const ArgumentInfo* argInfo);
 
  127     void invalidPrintfArgTypeError_n(
const Token* tok, 
nonneg int numFormat, 
const ArgumentInfo* argInfo);
 
  128     void invalidPrintfArgTypeError_p(
const Token* tok, 
nonneg int numFormat, 
const ArgumentInfo* argInfo);
 
  129     void invalidPrintfArgTypeError_uint(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo);
 
  130     void invalidPrintfArgTypeError_sint(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo);
 
  131     void invalidPrintfArgTypeError_float(
const Token* tok, 
nonneg int numFormat, 
const std::string& specifier, 
const ArgumentInfo* argInfo);
 
  132     void invalidLengthModifierError(
const Token* tok, 
nonneg int numFormat, 
const std::string& modifier);
 
  133     void invalidScanfFormatWidthError(
const Token* tok, 
nonneg int numFormat, 
int width, 
const Variable *var, 
const std::string& specifier);
 
  134     static void argumentType(std::ostream & os, 
const ArgumentInfo * argInfo);
 
  135     static Severity getSeverity(
const ArgumentInfo *argInfo);
 
  138         CheckIO c(
nullptr, settings, errorLogger);
 
  165         return "IO using format string";
 
  169         return "Check format string input/output operations.\n" 
  170                "- Bad usage of the function 'sprintf' (overlapping data)\n" 
  171                "- Missing or wrong width specifiers in 'scanf' format string\n" 
  172                "- Use a file that has been closed\n" 
  173                "- File input/output without positioning results in undefined behaviour\n" 
  174                "- Read to a file that has only been opened for writing (or vice versa)\n" 
  175                "- Repositioning operation on a file opened in append mode\n" 
  176                "- The same file can't be open for read and write at the same time on different streams\n" 
  177                "- Using fflush() on an input stream\n" 
  178                "- Invalid usage of output stream. For example: 'std::cout << std::cout;'\n" 
  179                "- Wrong number of arguments given to 'printf' or 'scanf;'\n";
 
ArgumentInfo(const ArgumentInfo &)=delete
 
Check input output operations.
 
void invalidPrintfArgTypeError_uint(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo)
 
void invalidScanf()
scanf can crash if width specifiers are not used
 
void invalidPrintfArgTypeError_n(const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo)
 
void seekOnAppendedFileError(const Token *tok)
 
void incompatibleFileOpenError(const Token *tok, const std::string &filename)
 
void invalidPrintfArgTypeError_s(const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo)
 
void writeReadOnlyFileError(const Token *tok)
 
void readWriteOnlyFileError(const Token *tok)
 
static std::string myName()
 
CheckIO(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
This constructor is used when running checks.
 
void invalidLengthModifierError(const Token *tok, nonneg int numFormat, const std::string &modifier)
 
void checkCoutCerrMisusage()
Check for missusage of std::cout
 
void fflushOnInputStreamError(const Token *tok, const std::string &varname)
 
void invalidScanfArgTypeError_float(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo)
 
void invalidScanfError(const Token *tok)
 
void wrongPrintfScanfPosixParameterPositionError(const Token *tok, const std::string &functionName, nonneg int index, nonneg int numFunction)
 
void invalidScanfFormatWidthError(const Token *tok, nonneg int numFormat, int width, const Variable *var, const std::string &specifier)
 
void invalidPrintfArgTypeError_sint(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo)
 
void coutCerrMisusageError(const Token *tok, const std::string &streamName)
 
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override
get error messages
 
void checkFileUsage()
Check usage of files
 
void checkWrongPrintfScanfArguments()
Checks type and number of arguments given to functions like printf or scanf
 
void invalidScanfArgTypeError_int(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo, bool isUnsigned)
 
void invalidPrintfArgTypeError_p(const Token *tok, nonneg int numFormat, const ArgumentInfo *argInfo)
 
void ioWithoutPositioningError(const Token *tok)
 
void invalidPrintfArgTypeError_float(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo)
 
void invalidScanfArgTypeError_s(const Token *tok, nonneg int numFormat, const std::string &specifier, const ArgumentInfo *argInfo)
 
void useClosedFileError(const Token *tok)
 
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override
Run checks on the normal token list.
 
void wrongPrintfScanfArgumentsError(const Token *tok, const std::string &functionName, nonneg int numFormat, nonneg int numFunction)
 
CheckIO()
This constructor is used when registering CheckIO.
 
std::string classInfo() const override
get information about this class, used to generate documentation
 
Interface class that cppcheck uses to communicate with the checks.
 
This is an interface, which the class responsible of error logging should implement.
 
This is just a container for general settings so that we don't need to pass individual values to func...
 
The token list that the TokenList generates is a linked-list of this class.
 
The main purpose is to tokenize the source code.
 
const Settings & getSettings() const
 
Information about a member variable.
 
Severity
enum class for severity.