diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index c7c32f248..e644e4401 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -37,6 +37,15 @@ extern bool ShowAll; // CallStack used when parsing into subfunctions. static std::list CallStack; +CheckBufferOverrunClass::CheckBufferOverrunClass( Tokenizer *tokenizer ) +{ + _tokenizer = tokenizer; +} + +CheckBufferOverrunClass::~CheckBufferOverrunClass() +{ + +} // Modified version of 'ReportError' that also reports the callstack void CheckBufferOverrunClass::ReportError(const TOKEN *tok, const char errmsg[]) diff --git a/CheckBufferOverrun.h b/CheckBufferOverrun.h index cf7f8fb76..ef8bdfc16 100644 --- a/CheckBufferOverrun.h +++ b/CheckBufferOverrun.h @@ -26,7 +26,10 @@ class CheckBufferOverrunClass { -public: +public: + CheckBufferOverrunClass( Tokenizer *tokenizer ); + ~CheckBufferOverrunClass(); + // Buffer overrun.. void CheckBufferOverrun(); @@ -38,7 +41,8 @@ private: void CheckBufferOverrun_LocalVariable(); void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname[], const int size, const int total_size ); void ReportError(const TOKEN *tok, const char errmsg[]); - + + Tokenizer *_tokenizer; }; //--------------------------------------------------------------------------- diff --git a/CheckClass.cpp b/CheckClass.cpp index 74af04958..a556e8c1b 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -100,6 +100,16 @@ struct VAR *CheckClass::ClassChecking_GetVarList(const TOKEN *tok1) return varlist; } //--------------------------------------------------------------------------- + +CheckClass::CheckClass( Tokenizer *tokenizer ) +{ + _tokenizer = tokenizer; +} + +CheckClass::~CheckClass() +{ + +} const TOKEN * CheckClass::FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel ) { diff --git a/CheckClass.h b/CheckClass.h index c3b7f64e3..47e55596e 100644 --- a/CheckClass.h +++ b/CheckClass.h @@ -33,7 +33,10 @@ struct VAR class CheckClass { -public: +public: + CheckClass( Tokenizer *tokenizer ); + ~CheckClass(); + void CheckConstructors(); void CheckUnusedPrivateFunctions(); @@ -47,6 +50,8 @@ private: void InitVar(struct VAR *varlist, const char varname[]); const TOKEN *FindClassFunction( const TOKEN *tok, const char classname[], const char funcname[], int &indentlevel ); struct VAR *ClassChecking_GetVarList(const TOKEN *tok1); + + Tokenizer *_tokenizer; }; //--------------------------------------------------------------------------- #endif diff --git a/CheckHeaders.cpp b/CheckHeaders.cpp index c0f39b7d8..ed45de8b6 100644 --- a/CheckHeaders.cpp +++ b/CheckHeaders.cpp @@ -34,6 +34,16 @@ //--------------------------------------------------------------------------- // HEADERS - No implementation in a header //--------------------------------------------------------------------------- + +CheckHeaders::CheckHeaders( Tokenizer *tokenizer ) +{ + _tokenizer = tokenizer; +} + +CheckHeaders::~CheckHeaders() +{ + +} void CheckHeaders::WarningHeaderWithImplementation() { diff --git a/CheckHeaders.h b/CheckHeaders.h index 6d72277a4..2405ed93e 100644 --- a/CheckHeaders.h +++ b/CheckHeaders.h @@ -22,12 +22,18 @@ #define CheckHeadersH //--------------------------------------------------------------------------- +#include "tokenize.h" + class CheckHeaders { -public: +public: + CheckHeaders( Tokenizer *tokenizer ); + ~CheckHeaders(); void WarningHeaderWithImplementation(); void WarningIncludeHeader(); - + +private: + Tokenizer *_tokenizer; }; //--------------------------------------------------------------------------- diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 21ca38761..4fcb2bd73 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -40,6 +40,16 @@ #endif //--------------------------------------------------------------------------- + +CheckMemoryLeakClass::CheckMemoryLeakClass( Tokenizer *tokenizer ) +{ + _tokenizer = tokenizer; +} + +CheckMemoryLeakClass::~CheckMemoryLeakClass() +{ + +} bool CheckMemoryLeakClass::isclass( const std::string &typestr ) { diff --git a/CheckMemoryLeak.h b/CheckMemoryLeak.h index d04882793..8a3192f4a 100644 --- a/CheckMemoryLeak.h +++ b/CheckMemoryLeak.h @@ -33,6 +33,8 @@ enum AllocType { No, Malloc, gMalloc, New, NewA }; class CheckMemoryLeakClass { public: + CheckMemoryLeakClass( Tokenizer *tokenizer ); + ~CheckMemoryLeakClass(); void CheckMemoryLeak(); private: @@ -53,6 +55,8 @@ private: AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[] ); AllocType GetAllocationType( const TOKEN *tok2 ); bool isclass( const std::string &typestr ); + + Tokenizer *_tokenizer; }; //--------------------------------------------------------------------------- diff --git a/CheckOther.cpp b/CheckOther.cpp index f93fb7843..197443585 100644 --- a/CheckOther.cpp +++ b/CheckOther.cpp @@ -34,6 +34,16 @@ //--------------------------------------------------------------------------- // Warning on C-Style casts.. p = (kalle *)foo; //--------------------------------------------------------------------------- + +CheckOther::CheckOther( Tokenizer *tokenizer ) +{ + _tokenizer = tokenizer; +} + +CheckOther::~CheckOther() +{ + +} void CheckOther::WarningOldStylePointerCast() { diff --git a/CheckOther.h b/CheckOther.h index 11350fd79..e08578057 100644 --- a/CheckOther.h +++ b/CheckOther.h @@ -27,7 +27,10 @@ class CheckOther { -public: +public: + CheckOther( Tokenizer *tokenizer ); + ~CheckOther(); + // Casting void WarningOldStylePointerCast(); @@ -70,7 +73,9 @@ public: // Incomplete statement. A statement that only contains a constant or variable void CheckIncompleteStatement(); private: - void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] ); + void CheckVariableScope_LookupVar( const TOKEN *tok1, const char varname[] ); + + Tokenizer *_tokenizer; }; //--------------------------------------------------------------------------- diff --git a/main.cpp b/main.cpp index e38a64d80..bb0d05780 100644 --- a/main.cpp +++ b/main.cpp @@ -177,13 +177,13 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in // 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; + CheckClass checkClass( &tokenizer ); checkClass.CheckMemset(); // Check for unsigned divisions where one operand is signed // Very important to run it before 'SimplifyTokenList' - CheckOther checkOther; + CheckOther checkOther( &tokenizer ); checkOther.CheckUnsignedDivision(); // Give warning when using char variable as array index @@ -195,7 +195,7 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in // Including header which is not needed (too many false positives) // if ( CheckCodingStyle ) // { -// CheckHeaders checkHeaders; +// CheckHeaders checkHeaders( &tokenizer ); // checkHeaders.WarningIncludeHeader(); // } @@ -203,11 +203,11 @@ static void CppCheck(const std::string &code, const char FileName[], unsigned in tokenizer.SimplifyTokenList(); // Memory leak - CheckMemoryLeakClass checkMemoryLeak; + CheckMemoryLeakClass checkMemoryLeak( &tokenizer ); checkMemoryLeak.CheckMemoryLeak(); // Buffer overruns.. - CheckBufferOverrunClass checkBufferOverrun; + CheckBufferOverrunClass checkBufferOverrun( &tokenizer ); checkBufferOverrun.CheckBufferOverrun(); // Check that all class constructors are ok. diff --git a/testbufferoverrun.cpp b/testbufferoverrun.cpp index 9647657ef..172594035 100644 --- a/testbufferoverrun.cpp +++ b/testbufferoverrun.cpp @@ -52,7 +52,7 @@ private: // Check for memory leaks.. ShowAll = true; - CheckBufferOverrunClass checkBufferOverrun; + CheckBufferOverrunClass checkBufferOverrun( &tokenizer ); checkBufferOverrun.CheckBufferOverrun(); tokenizer.DeallocateTokens(); diff --git a/testcharvar.cpp b/testcharvar.cpp index c61f48570..62eb501f9 100644 --- a/testcharvar.cpp +++ b/testcharvar.cpp @@ -57,7 +57,7 @@ private: // Check for memory leaks.. ShowAll = true; - CheckOther checkOther; + CheckOther checkOther( &tokenizer ); checkOther.CheckCharVariable(); tokenizer.DeallocateTokens(); diff --git a/testconstructors.cpp b/testconstructors.cpp index 22e4c456a..d22f48e2a 100644 --- a/testconstructors.cpp +++ b/testconstructors.cpp @@ -46,7 +46,7 @@ private: errout.str(""); // Check for memory leaks.. - CheckClass checkClass; + CheckClass checkClass( &tokenizer ); checkClass.CheckConstructors(); tokenizer.DeallocateTokens(); diff --git a/testdivision.cpp b/testdivision.cpp index 31ffd11bb..d1931f044 100644 --- a/testdivision.cpp +++ b/testdivision.cpp @@ -51,7 +51,7 @@ private: // Check for memory leaks.. ShowAll = true; - CheckOther checkOther; + CheckOther checkOther( &tokenizer ); checkOther.CheckUnsignedDivision(); tokenizer.DeallocateTokens(); diff --git a/testincompletestatement.cpp b/testincompletestatement.cpp index 64c91f2ef..8dd05af0b 100644 --- a/testincompletestatement.cpp +++ b/testincompletestatement.cpp @@ -48,7 +48,7 @@ private: errout.str(""); // Check for unused variables.. - CheckOther checkOther; + CheckOther checkOther( &tokenizer ); checkOther.CheckIncompleteStatement(); tokenizer.DeallocateTokens(); diff --git a/testmemleak.cpp b/testmemleak.cpp index 0c4f3e168..44b3f95fa 100644 --- a/testmemleak.cpp +++ b/testmemleak.cpp @@ -51,7 +51,7 @@ private: // Check for memory leaks.. ShowAll = false; FillFunctionList(0); - CheckMemoryLeakClass checkMemoryLeak; + CheckMemoryLeakClass checkMemoryLeak( &tokenizer ); checkMemoryLeak.CheckMemoryLeak(); tokenizer.DeallocateTokens(); diff --git a/testunusedprivfunc.cpp b/testunusedprivfunc.cpp index 787308b07..d01e11603 100644 --- a/testunusedprivfunc.cpp +++ b/testunusedprivfunc.cpp @@ -54,7 +54,7 @@ private: errout.str(""); // Check for unused private functions.. - CheckClass checkClass; + CheckClass checkClass( &tokenizer ); checkClass.CheckUnusedPrivateFunctions(); tokenizer.DeallocateTokens(); diff --git a/testunusedvar.cpp b/testunusedvar.cpp index 233bac99a..38839ebcc 100644 --- a/testunusedvar.cpp +++ b/testunusedvar.cpp @@ -48,7 +48,7 @@ private: errout.str(""); // Check for unused variables.. - CheckOther checkOther; + CheckOther checkOther( &tokenizer ); checkOther.CheckStructMemberUsage(); tokenizer.DeallocateTokens(); diff --git a/tokenize.h b/tokenize.h index 228c94880..bc90daf03 100644 --- a/tokenize.h +++ b/tokenize.h @@ -85,7 +85,9 @@ public: // Return size. static int SizeOfType(const char type[]); - + std::vector _files; + TOKEN *_tokens; + TOKEN *_tokens_back; private: