refactoring: Renamed checking classes

This commit is contained in:
Daniel Marjamäki 2009-07-13 16:00:15 +02:00
parent 2ee8be9f7f
commit 18f9e05f5a
6 changed files with 29 additions and 29 deletions

View File

@ -38,39 +38,39 @@
// Register this check class (by creating a static instance of it) // Register this check class (by creating a static instance of it)
namespace namespace
{ {
CheckBufferOverrunClass instance; CheckBufferOverrun instance;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok) void CheckBufferOverrun::arrayIndexOutOfBounds(const Token *tok)
{ {
_callStack.push_back(tok); _callStack.push_back(tok);
arrayIndexOutOfBounds(); arrayIndexOutOfBounds();
_callStack.pop_back(); _callStack.pop_back();
} }
void CheckBufferOverrunClass::arrayIndexOutOfBounds() void CheckBufferOverrun::arrayIndexOutOfBounds()
{ {
reportError(_callStack, Severity::possibleError, "arrayIndexOutOfBounds", "Array index out of bounds"); reportError(_callStack, Severity::possibleError, "arrayIndexOutOfBounds", "Array index out of bounds");
} }
void CheckBufferOverrunClass::bufferOverrun(const Token *tok) void CheckBufferOverrun::bufferOverrun(const Token *tok)
{ {
reportError(tok, Severity::possibleError, "bufferOverrun", "Buffer overrun"); reportError(tok, Severity::possibleError, "bufferOverrun", "Buffer overrun");
} }
void CheckBufferOverrunClass::strncatUsage(const Token *tok) void CheckBufferOverrun::strncatUsage(const Token *tok)
{ {
reportError(tok, Severity::possibleError, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append"); reportError(tok, Severity::possibleError, "strncatUsage", "Dangerous usage of strncat. Tip: the 3rd parameter means maximum number of characters to append");
} }
void CheckBufferOverrunClass::outOfBounds(const Token *tok, const std::string &what) void CheckBufferOverrun::outOfBounds(const Token *tok, const std::string &what)
{ {
reportError(tok, Severity::error, "outOfBounds", what + " is out of bounds"); reportError(tok, Severity::error, "outOfBounds", what + " is out of bounds");
} }
void CheckBufferOverrunClass::sizeArgumentAsChar(const Token *tok) void CheckBufferOverrun::sizeArgumentAsChar(const Token *tok)
{ {
reportError(tok, Severity::possibleError, "sizeArgumentAsChar", "The size argument is given as a char constant"); reportError(tok, Severity::possibleError, "sizeArgumentAsChar", "The size argument is given as a char constant");
} }
@ -82,7 +82,7 @@ void CheckBufferOverrunClass::sizeArgumentAsChar(const Token *tok)
// Check array usage.. // Check array usage..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::checkScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid) void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], const int size, const int total_size, unsigned int varid)
{ {
unsigned int varc = 0; unsigned int varc = 0;
@ -440,7 +440,7 @@ void CheckBufferOverrunClass::checkScope(const Token *tok, const char *varname[]
// Checking local variables in a scope // Checking local variables in a scope
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::checkGlobalAndLocalVariable() void CheckBufferOverrun::checkGlobalAndLocalVariable()
{ {
int indentlevel = 0; int indentlevel = 0;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
@ -509,7 +509,7 @@ void CheckBufferOverrunClass::checkGlobalAndLocalVariable()
// Checking member variables of structs.. // Checking member variables of structs..
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::checkStructVariable() void CheckBufferOverrun::checkStructVariable()
{ {
const char declstruct[] = "struct|class %var% {"; const char declstruct[] = "struct|class %var% {";
for (const Token *tok = Token::findmatch(_tokenizer->tokens(), declstruct); for (const Token *tok = Token::findmatch(_tokenizer->tokens(), declstruct);
@ -622,7 +622,7 @@ void CheckBufferOverrunClass::checkStructVariable()
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckBufferOverrunClass::bufferOverrun() void CheckBufferOverrun::bufferOverrun()
{ {
checkGlobalAndLocalVariable(); checkGlobalAndLocalVariable();
checkStructVariable(); checkStructVariable();

View File

@ -30,24 +30,24 @@ class ErrorLogger;
class Token; class Token;
class Tokenizer; class Tokenizer;
class CheckBufferOverrunClass : public Check class CheckBufferOverrun : public Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckClass */
CheckBufferOverrunClass() : Check() CheckBufferOverrun() : Check()
{ } { }
/** This constructor is used when running checks.. */ /** This constructor is used when running checks.. */
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(tokenizer, settings, errorLogger)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
{ {
CheckBufferOverrunClass checkBufferOverrunClass(tokenizer, settings, errorLogger); CheckBufferOverrun checkBufferOverrun(tokenizer, settings, errorLogger);
if (settings->_showAll) if (settings->_showAll)
checkBufferOverrunClass.bufferOverrun(); checkBufferOverrun.bufferOverrun();
} }
/** Check for buffer overruns */ /** Check for buffer overruns */

View File

@ -28,10 +28,10 @@
// Register this check class (by creating a static instance of it) // Register this check class (by creating a static instance of it)
namespace namespace
{ {
CheckDangerousFunctionsClass instance; CheckDangerousFunctions instance;
} }
void CheckDangerousFunctionsClass::dangerousFunctions() void CheckDangerousFunctions::dangerousFunctions()
{ {
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{ {
@ -52,17 +52,17 @@ void CheckDangerousFunctionsClass::dangerousFunctions()
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
void CheckDangerousFunctionsClass::dangerousFunctionmktemp(const Token *tok) void CheckDangerousFunctions::dangerousFunctionmktemp(const Token *tok)
{ {
reportError(tok, Severity::style, "dangerousFunctionmktemp", "Found 'mktemp'. You should use 'mkstemp' instead"); reportError(tok, Severity::style, "dangerousFunctionmktemp", "Found 'mktemp'. You should use 'mkstemp' instead");
} }
void CheckDangerousFunctionsClass::dangerousFunctiongets(const Token *tok) void CheckDangerousFunctions::dangerousFunctiongets(const Token *tok)
{ {
reportError(tok, Severity::style, "dangerousFunctiongets", "Found 'gets'. You should use 'fgets' instead"); reportError(tok, Severity::style, "dangerousFunctiongets", "Found 'gets'. You should use 'fgets' instead");
} }
void CheckDangerousFunctionsClass::dangerousFunctionscanf(const Token *tok) void CheckDangerousFunctions::dangerousFunctionscanf(const Token *tok)
{ {
reportError(tok, Severity::style, "dangerousFunctionscanf", "Found 'scanf'. You should use 'fgets' instead"); reportError(tok, Severity::style, "dangerousFunctionscanf", "Found 'scanf'. You should use 'fgets' instead");
} }

View File

@ -24,24 +24,24 @@
#include "check.h" #include "check.h"
class CheckDangerousFunctionsClass : public Check class CheckDangerousFunctions : public Check
{ {
public: public:
/** This constructor is used when registering the CheckClass */ /** This constructor is used when registering the CheckDangerousFunctions */
CheckDangerousFunctionsClass() : Check() CheckDangerousFunctions() : Check()
{ } { }
/** This constructor is used when running checks.. */ /** This constructor is used when running checks.. */
CheckDangerousFunctionsClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) CheckDangerousFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger) : Check(tokenizer, settings, errorLogger)
{ } { }
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
{ {
CheckDangerousFunctionsClass checkDangerousFunctionsClass(tokenizer, settings, errorLogger); CheckDangerousFunctions checkDangerousFunctions(tokenizer, settings, errorLogger);
if (settings->_checkCodingStyle) if (settings->_checkCodingStyle)
{ {
checkDangerousFunctionsClass.dangerousFunctions(); checkDangerousFunctions.dangerousFunctions();
} }
} }

View File

@ -55,7 +55,7 @@ private:
// Check for buffer overruns.. // Check for buffer overruns..
Settings settings; Settings settings;
settings._showAll = true; settings._showAll = true;
CheckBufferOverrunClass checkBufferOverrun(&tokenizer, &settings, this); CheckBufferOverrun checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.bufferOverrun(); checkBufferOverrun.bufferOverrun();
} }

View File

@ -55,7 +55,7 @@ private:
// Check for dangerous functions.. // Check for dangerous functions..
Settings settings; Settings settings;
settings._showAll = true; settings._showAll = true;
CheckDangerousFunctionsClass checkDangerousFunctions(&tokenizer, &settings, this); CheckDangerousFunctions checkDangerousFunctions(&tokenizer, &settings, this);
checkDangerousFunctions.dangerousFunctions(); checkDangerousFunctions.dangerousFunctions();
} }