Few static variables are now private members. ShowAll etc. global variables are now members of Settings class and given as a
parameter to the classes that need them.
This commit is contained in:
parent
2ecb805283
commit
ce08224547
|
@ -30,12 +30,10 @@
|
|||
|
||||
#include <stdlib.h> // <- strtoul
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
extern bool ShowAll;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// CallStack used when parsing into subfunctions.
|
||||
static std::list<const TOKEN *> CallStack;
|
||||
|
||||
|
||||
CheckBufferOverrunClass::CheckBufferOverrunClass( Tokenizer *tokenizer )
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@ private:
|
|||
void ReportError(const TOKEN *tok, const char errmsg[]);
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
std::list<const TOKEN *> CallStack;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -34,8 +34,16 @@
|
|||
#endif
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
extern bool CheckCodingStyle;
|
||||
CheckClass::CheckClass( Tokenizer *tokenizer, const Settings &settings )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
CheckClass::~CheckClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
@ -101,16 +109,6 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1)
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckClass::CheckClass( Tokenizer *tokenizer )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
CheckClass::~CheckClass()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel )
|
||||
{
|
||||
const char *_classname[2] = {0,0};
|
||||
|
@ -332,7 +330,7 @@ void CheckClass::CheckConstructors()
|
|||
if ( ! constructor_token )
|
||||
{
|
||||
// There's no class constructor
|
||||
if ( CheckCodingStyle )
|
||||
if ( _settings._checkCodingStyle )
|
||||
{
|
||||
// Check that all member variables are initialized..
|
||||
struct VAR *varlist = ClassChecking_GetVarList(tok1);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "tokenize.h"
|
||||
#include "settings.h"
|
||||
#include <list>
|
||||
|
||||
struct VAR
|
||||
|
@ -34,7 +35,7 @@ struct VAR
|
|||
class CheckClass
|
||||
{
|
||||
public:
|
||||
CheckClass( Tokenizer *tokenizer );
|
||||
CheckClass( Tokenizer *tokenizer, const Settings &settings );
|
||||
~CheckClass();
|
||||
|
||||
void CheckConstructors();
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
struct VAR *ClassChecking_GetVarList(const TOKEN *tok1);
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
Settings _settings;
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
|
|
@ -41,9 +41,10 @@
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CheckMemoryLeakClass::CheckMemoryLeakClass( Tokenizer *tokenizer )
|
||||
CheckMemoryLeakClass::CheckMemoryLeakClass( Tokenizer *tokenizer, const Settings &settings )
|
||||
{
|
||||
_tokenizer = tokenizer;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
CheckMemoryLeakClass::~CheckMemoryLeakClass()
|
||||
|
@ -281,9 +282,6 @@ bool CheckMemoryLeakClass::notvar(const TOKEN *tok, const char *varnames[])
|
|||
Match(tok, "%var1% == 0", varnames) );
|
||||
}
|
||||
|
||||
|
||||
extern bool ShowAll;
|
||||
|
||||
/**
|
||||
* Extract a new tokens list that is easier to parse than the "tokens"
|
||||
* tok - start parse token
|
||||
|
@ -344,7 +342,7 @@ TOKEN *CheckMemoryLeakClass::getcode(const TOKEN *tok, std::list<const TOKEN *>
|
|||
AllocType alloc = GetAllocationType(Tokenizer::gettok(tok,3));
|
||||
|
||||
// If "--all" hasn't been given, don't check classes..
|
||||
if ( alloc == New && ! ShowAll )
|
||||
if ( alloc == New && ! _settings._showAll )
|
||||
{
|
||||
if ( Match(Tokenizer::gettok(tok,3), "new %type% [(;]") )
|
||||
{
|
||||
|
@ -941,7 +939,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_ParseClass( const TOKEN
|
|||
{
|
||||
if ( IsName(tok->str) || strchr(";}", tok->str[0]) )
|
||||
{
|
||||
if (ShowAll || !isclass(Tokenizer::getstr(tok,1)))
|
||||
if (_settings._showAll || !isclass(Tokenizer::getstr(tok,1)))
|
||||
CheckMemoryLeak_ClassMembers_Variable( classname, Tokenizer::getstr(tok, 3) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
/** \brief Check for memory leaks */
|
||||
|
||||
#include "tokenize.h"
|
||||
#include "settings.h"
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
@ -34,7 +35,7 @@ enum AllocType { No, Malloc, gMalloc, New, NewA };
|
|||
class CheckMemoryLeakClass
|
||||
{
|
||||
public:
|
||||
CheckMemoryLeakClass( Tokenizer *tokenizer );
|
||||
CheckMemoryLeakClass( Tokenizer *tokenizer, const Settings &settings );
|
||||
~CheckMemoryLeakClass();
|
||||
void CheckMemoryLeak();
|
||||
|
||||
|
@ -58,6 +59,7 @@ private:
|
|||
bool isclass( const std::string &typestr );
|
||||
|
||||
Tokenizer *_tokenizer;
|
||||
Settings _settings;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
16
cppcheck.cpp
16
cppcheck.cpp
|
@ -34,12 +34,6 @@
|
|||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
bool Debug = false;
|
||||
bool ShowAll = false;
|
||||
bool CheckCodingStyle = false;
|
||||
bool ErrorsOnly = false;
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
CppCheck::CppCheck()
|
||||
|
@ -83,10 +77,6 @@ void CppCheck::check(int argc, char* argv[])
|
|||
pathnames.push_back( argv[i] );
|
||||
}
|
||||
|
||||
Debug = _settings._debug;
|
||||
ShowAll = _settings._showAll;
|
||||
CheckCodingStyle = _settings._checkCodingStyle;
|
||||
ErrorsOnly = _settings._errorsOnly;
|
||||
_tokenizer.settings( _settings );
|
||||
|
||||
std::vector<std::string> filenames;
|
||||
|
@ -206,7 +196,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[], unsigne
|
|||
// Check that the memsets are valid.
|
||||
// The 'memset' function can do dangerous things if used wrong.
|
||||
// Important: The checking doesn't work on simplified tokens list.
|
||||
CheckClass checkClass( &_tokenizer );
|
||||
CheckClass checkClass( &_tokenizer, _settings );
|
||||
checkClass.CheckMemset();
|
||||
|
||||
|
||||
|
@ -222,7 +212,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[], unsigne
|
|||
|
||||
|
||||
// Including header which is not needed (too many false positives)
|
||||
// if ( CheckCodingStyle )
|
||||
// if ( _settings._checkCodingStyle )
|
||||
// {
|
||||
// CheckHeaders checkHeaders( &tokenizer );
|
||||
// checkHeaders.WarningIncludeHeader();
|
||||
|
@ -232,7 +222,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[], unsigne
|
|||
_tokenizer.SimplifyTokenList();
|
||||
|
||||
// Memory leak
|
||||
CheckMemoryLeakClass checkMemoryLeak( &_tokenizer );
|
||||
CheckMemoryLeakClass checkMemoryLeak( &_tokenizer, _settings );
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
// Buffer overruns..
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern bool ShowAll;
|
||||
|
||||
class TestBufferOverrun : public TestFixture
|
||||
{
|
||||
|
@ -54,7 +53,6 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckBufferOverrunClass checkBufferOverrun( &tokenizer );
|
||||
checkBufferOverrun.CheckBufferOverrun();
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern bool ShowAll;
|
||||
|
||||
class TestCharVar : public TestFixture
|
||||
{
|
||||
|
@ -59,7 +58,6 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckCharVariable();
|
||||
|
||||
|
|
|
@ -46,7 +46,9 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
CheckClass checkClass( &tokenizer );
|
||||
Settings settings;
|
||||
settings._checkCodingStyle = true;
|
||||
CheckClass checkClass( &tokenizer, settings );
|
||||
checkClass.CheckConstructors();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern bool ShowAll;
|
||||
|
||||
class TestDivision : public TestFixture
|
||||
{
|
||||
|
@ -50,7 +49,6 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
ShowAll = true;
|
||||
CheckOther checkOther( &tokenizer );
|
||||
checkOther.CheckUnsignedDivision();
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern bool ShowAll;
|
||||
|
||||
class TestMemleak : public TestFixture
|
||||
{
|
||||
|
@ -49,12 +48,12 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for memory leaks..
|
||||
ShowAll = false;
|
||||
Settings settings;
|
||||
settings._checkCodingStyle = true;
|
||||
settings._showAll = false;
|
||||
tokenizer.settings( settings );
|
||||
tokenizer.FillFunctionList(0);
|
||||
CheckMemoryLeakClass checkMemoryLeak( &tokenizer );
|
||||
CheckMemoryLeakClass checkMemoryLeak( &tokenizer, settings );
|
||||
checkMemoryLeak.CheckMemoryLeak();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -21,13 +21,8 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern bool ShowAll;
|
||||
extern bool CheckCodingStyle;
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
ShowAll = false;
|
||||
CheckCodingStyle = true;
|
||||
TestFixture::runTests( (argc==2) ? argv[1] : NULL );
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <sstream>
|
||||
|
||||
extern std::ostringstream errout;
|
||||
extern bool ShowAll;
|
||||
|
||||
class TestUnusedPrivateFunction : public TestFixture
|
||||
{
|
||||
|
@ -54,7 +53,9 @@ private:
|
|||
errout.str("");
|
||||
|
||||
// Check for unused private functions..
|
||||
CheckClass checkClass( &tokenizer );
|
||||
Settings settings;
|
||||
settings._checkCodingStyle = true;
|
||||
CheckClass checkClass( &tokenizer, settings );
|
||||
checkClass.CheckUnusedPrivateFunctions();
|
||||
|
||||
tokenizer.DeallocateTokens();
|
||||
|
|
|
@ -69,6 +69,7 @@ Tokenizer::Tokenizer()
|
|||
{
|
||||
tokens = 0;
|
||||
tokens_back = 0;
|
||||
dsymlist = 0;
|
||||
}
|
||||
|
||||
Tokenizer::~Tokenizer()
|
||||
|
@ -81,13 +82,7 @@ Tokenizer::~Tokenizer()
|
|||
// "#define abc 123" will create a defined symbol "abc" with the value 123
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
struct DefineSymbol
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
struct DefineSymbol *next;
|
||||
};
|
||||
static struct DefineSymbol * dsymlist;
|
||||
|
||||
|
||||
std::vector<std::string> *Tokenizer::getFiles()
|
||||
{
|
||||
|
|
12
tokenize.h
12
tokenize.h
|
@ -94,11 +94,16 @@ public:
|
|||
|
||||
void FillFunctionList(const unsigned int file_id);
|
||||
const TOKEN *GetFunctionTokenByName( const char funcname[] ) const;
|
||||
void CheckGlobalFunctionUsage(const std::vector<std::string> &filenames);
|
||||
void CheckGlobalFunctionUsage(const std::vector<std::string> &filenames);
|
||||
void settings( const Settings &settings );
|
||||
private:
|
||||
|
||||
|
||||
struct DefineSymbol
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
struct DefineSymbol *next;
|
||||
};
|
||||
|
||||
class GlobalFunction
|
||||
{
|
||||
|
@ -136,6 +141,9 @@ private:
|
|||
std::list< GlobalFunction > UsedGlobalFunctions;
|
||||
std::vector<std::string> Files;
|
||||
Settings _settings;
|
||||
|
||||
|
||||
struct DefineSymbol * dsymlist;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue