refactoring checkbufferoverrun

This commit is contained in:
Daniel Marjamäki 2009-03-20 17:35:53 +01:00
parent 5914af4481
commit 21dff96e7b
4 changed files with 18 additions and 31 deletions

View File

@ -36,20 +36,6 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// _callStack used when parsing into subfunctions.
CheckBufferOverrunClass::CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger)
: _settings(settings)
{
_tokenizer = tokenizer;
_errorLogger = errorLogger;
}
CheckBufferOverrunClass::~CheckBufferOverrunClass()
{
}
void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok) void CheckBufferOverrunClass::arrayIndexOutOfBounds(const Token *tok)
{ {
@ -323,7 +309,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
continue; continue;
// Only perform this checking if showAll setting is enabled.. // Only perform this checking if showAll setting is enabled..
if (!_settings._showAll) if (!_settings->_showAll)
continue; continue;
unsigned int parlevel = 0, par = 0; unsigned int parlevel = 0, par = 0;

View File

@ -23,6 +23,7 @@
#define CheckBufferOverrunH #define CheckBufferOverrunH
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "check.h"
#include "settings.h" #include "settings.h"
#include <list> #include <list>
@ -30,11 +31,23 @@ class ErrorLogger;
class Token; class Token;
class Tokenizer; class Tokenizer;
class CheckBufferOverrunClass class CheckBufferOverrunClass : public Check
{ {
public: public:
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger);
~CheckBufferOverrunClass(); CheckBufferOverrunClass() : Check()
{ }
CheckBufferOverrunClass(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(tokenizer, settings, errorLogger)
{ }
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
{
CheckBufferOverrunClass checkBufferOverrunClass(tokenizer, settings, errorLogger);
if (settings->_showAll)
checkBufferOverrunClass.bufferOverrun();
}
/** Check for buffer overruns */ /** Check for buffer overruns */
void bufferOverrun(); void bufferOverrun();
@ -49,10 +62,6 @@ private:
/** Check for buffer overruns - this is the function that performs the actual checking */ /** Check for buffer overruns - this is the function that performs the actual checking */
void CheckBufferOverrun_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);
const Tokenizer *_tokenizer;
const Settings _settings;
ErrorLogger *_errorLogger;
/** callstack - used during intra-function checking */ /** callstack - used during intra-function checking */
std::list<const Token *> _callStack; std::list<const Token *> _callStack;

View File

@ -22,7 +22,6 @@
#include "tokenize.h" // <- Tokenizer #include "tokenize.h" // <- Tokenizer
#include "checkmemoryleak.h" #include "checkmemoryleak.h"
#include "checkbufferoverrun.h"
#include "checkdangerousfunctions.h" #include "checkdangerousfunctions.h"
#include "checkheaders.h" #include "checkheaders.h"
#include "checkother.h" #include "checkother.h"
@ -402,9 +401,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (_settings._unusedFunctions) if (_settings._unusedFunctions)
_checkFunctionUsage.parseTokens(_tokenizer); _checkFunctionUsage.parseTokens(_tokenizer);
// Class for detecting buffer overruns and related problems
CheckBufferOverrunClass checkBufferOverrun(&_tokenizer, _settings, this);
// Class for checking functions that should not be used // Class for checking functions that should not be used
CheckDangerousFunctionsClass checkDangerousFunctions(&_tokenizer, _settings, this); CheckDangerousFunctionsClass checkDangerousFunctions(&_tokenizer, _settings, this);
@ -413,10 +409,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc()) if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
checkMemoryLeak.CheckMemoryLeak(); checkMemoryLeak.CheckMemoryLeak();
// Array index out of bounds / Buffer overruns..
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
checkBufferOverrun.bufferOverrun();
// Warning upon c-style pointer casts // Warning upon c-style pointer casts
if (ErrorLogger::cstyleCast(_settings)) if (ErrorLogger::cstyleCast(_settings))
{ {

View File

@ -56,7 +56,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); CheckBufferOverrunClass checkBufferOverrun(&tokenizer, &settings, this);
checkBufferOverrun.bufferOverrun(); checkBufferOverrun.bufferOverrun();
} }