refactoring checkbufferoverrun
This commit is contained in:
parent
5914af4481
commit
21dff96e7b
|
@ -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)
|
||||
{
|
||||
|
@ -323,7 +309,7 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope(const Token *tok, co
|
|||
continue;
|
||||
|
||||
// Only perform this checking if showAll setting is enabled..
|
||||
if (!_settings._showAll)
|
||||
if (!_settings->_showAll)
|
||||
continue;
|
||||
|
||||
unsigned int parlevel = 0, par = 0;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#define CheckBufferOverrunH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "check.h"
|
||||
#include "settings.h"
|
||||
#include <list>
|
||||
|
||||
|
@ -30,11 +31,23 @@ class ErrorLogger;
|
|||
class Token;
|
||||
class Tokenizer;
|
||||
|
||||
class CheckBufferOverrunClass
|
||||
class CheckBufferOverrunClass : public Check
|
||||
{
|
||||
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 */
|
||||
void bufferOverrun();
|
||||
|
@ -49,10 +62,6 @@ private:
|
|||
/** 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);
|
||||
|
||||
const Tokenizer *_tokenizer;
|
||||
const Settings _settings;
|
||||
ErrorLogger *_errorLogger;
|
||||
|
||||
/** callstack - used during intra-function checking */
|
||||
std::list<const Token *> _callStack;
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "tokenize.h" // <- Tokenizer
|
||||
|
||||
#include "checkmemoryleak.h"
|
||||
#include "checkbufferoverrun.h"
|
||||
#include "checkdangerousfunctions.h"
|
||||
#include "checkheaders.h"
|
||||
#include "checkother.h"
|
||||
|
@ -402,9 +401,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (_settings._unusedFunctions)
|
||||
_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
|
||||
CheckDangerousFunctionsClass checkDangerousFunctions(&_tokenizer, _settings, this);
|
||||
|
||||
|
@ -413,10 +409,6 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
if (ErrorLogger::memleak() || ErrorLogger::mismatchAllocDealloc())
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
// Array index out of bounds / Buffer overruns..
|
||||
if (ErrorLogger::arrayIndexOutOfBounds(_settings) || ErrorLogger::bufferOverrun(_settings))
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
|
||||
// Warning upon c-style pointer casts
|
||||
if (ErrorLogger::cstyleCast(_settings))
|
||||
{
|
||||
|
|
|
@ -56,7 +56,7 @@ private:
|
|||
// Check for buffer overruns..
|
||||
Settings settings;
|
||||
settings._showAll = true;
|
||||
CheckBufferOverrunClass checkBufferOverrun(&tokenizer, settings, this);
|
||||
CheckBufferOverrunClass checkBufferOverrun(&tokenizer, &settings, this);
|
||||
checkBufferOverrun.bufferOverrun();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue