diff --git a/CheckClass.cpp b/CheckClass.cpp index ae7c320d9..d112f3eeb 100644 --- a/CheckClass.cpp +++ b/CheckClass.cpp @@ -92,6 +92,12 @@ static struct VAR *ClassChecking_GetVarList(const char classname[]) static const TOKEN * FindClassFunction( const TOKEN *_tokens, const char classname[], const char funcname[], unsigned int &indentlevel ) { + const char *_classname[2] = {0,0}; + const char *_funcname[2] = {0,0}; + _classname[0] = classname; + _funcname[0] = funcname; + + while ( _tokens ) { if ( indentlevel > 0 ) @@ -103,7 +109,7 @@ static const TOKEN * FindClassFunction( const TOKEN *_tokens, const char classna else if ( indentlevel == 1 ) { // Member function is implemented in the class declaration.. - if ( Match( _tokens, "%var% (" ) && strcmp(_tokens->str,funcname) == 0 ) + if ( Match( _tokens, "%var1% (", _funcname ) ) { const TOKEN *tok2 = _tokens; while ( tok2 && tok2->str[0] != '{' && tok2->str[0] != ';' ) @@ -114,17 +120,13 @@ static const TOKEN * FindClassFunction( const TOKEN *_tokens, const char classna } } - // Todo: Match the classname directly instead - else if ( Match(_tokens, "class %var% {") && strcmp(getstr(_tokens,1),classname)==0 ) + else if ( Match(_tokens, "class %var1% {", _classname) ) { indentlevel = 1; _tokens = gettok( _tokens, 2 ); } - // Todo: Match the classname and funcname directly instead - else if ( Match(_tokens, "%var% :: %var% (") && - strcmp(_tokens->str,classname) == 0 && - strcmp(getstr(_tokens,2),funcname) == 0 ) + else if ( Match(_tokens, "%var1% :: %var2% (", _classname, _funcname) ) { return _tokens; } diff --git a/CommonCheck.cpp b/CommonCheck.cpp index 584f0ae64..5ede08175 100644 --- a/CommonCheck.cpp +++ b/CommonCheck.cpp @@ -6,10 +6,9 @@ #include #include //--------------------------------------------------------------------------- -bool HasErrors; bool OnlyReportUniqueErrors; std::ostringstream errout; -std::list FunctionList; +static std::list FunctionList; //--------------------------------------------------------------------------- std::string FileLine(const TOKEN *tok) @@ -31,7 +30,6 @@ void ReportErr(const std::string &errmsg) ErrorList.push_back( errmsg ); } errout << errmsg << std::endl; - HasErrors = true; } //--------------------------------------------------------------------------- @@ -61,6 +59,8 @@ bool IsStandardType(const char str[]) void FillFunctionList() { + FunctionList.clear(); + int indentlevel = 0; for ( const TOKEN *tok = tokens; tok; tok = tok->next ) { @@ -121,7 +121,7 @@ const TOKEN *GetFunctionTokenByName( const char funcname[] ) } //--------------------------------------------------------------------------- -bool Match(const TOKEN *tok, const char pattern[], const char *varname[]) +bool Match(const TOKEN *tok, const char pattern[], const char *varname1[], const char *varname2[]) { if (!tok) return false; @@ -156,8 +156,13 @@ bool Match(const TOKEN *tok, const char pattern[], const char *varname[]) } // Variable name.. - else if (strcmp(str,"%var1%")==0) + else if (strcmp(str,"%var1%")==0 || strcmp(str,"%var2%")==0) { + const char **varname = (strcmp(str,"%var1%")==0) ? varname1 : varname2; + + if ( ! varname ) + return false; + if (strcmp(tok->str, varname[0]) != 0) return false; diff --git a/CommonCheck.h b/CommonCheck.h index b2128aad6..d605dda6f 100644 --- a/CommonCheck.h +++ b/CommonCheck.h @@ -9,8 +9,6 @@ struct TOKEN; -extern std::list FunctionList; - std::string FileLine(const TOKEN *tok); extern bool OnlyReportUniqueErrors; @@ -28,7 +26,7 @@ void FillFunctionList(); const TOKEN *GetFunctionTokenByName( const char funcname[] ); -bool Match(const TOKEN *tok, const char pattern[], const char *varname[]=0); +bool Match(const TOKEN *tok, const char pattern[], const char *varname1[]=0, const char *varname2[]=0); //--------------------------------------------------------------------------- diff --git a/main.cpp b/main.cpp index e800d6f35..79c8a69b5 100644 --- a/main.cpp +++ b/main.cpp @@ -164,11 +164,8 @@ int main(int argc, char* argv[]) // CppCheck - A function that checks a specified file //--------------------------------------------------------------------------- -extern bool HasErrors; - static void CppCheck(const char FileName[]) { - HasErrors = false; OnlyReportUniqueErrors = true; std::cout << "Checking " << FileName << "...\n"; @@ -178,7 +175,7 @@ static void CppCheck(const char FileName[]) Files.clear(); Tokenize(FileName); - FunctionList.clear(); + FillFunctionList(); // Check that the memsets are valid. // The 'memset' function can do dangerous things if used wrong. @@ -242,11 +239,7 @@ static void CppCheck(const char FileName[]) // Warning upon c-style pointer casts const char *ext = strrchr(FileName, '.'); -#ifdef __linux__ - if (ext && strcasecmp(ext,".c")) -#else - if (ext && stricmp(ext,".c")) -#endif + if (ext && strcmp(ext,".cpp")==0) WarningOldStylePointerCast(); // Use standard functions instead @@ -269,8 +262,7 @@ static void CppCheck(const char FileName[]) // Clean up tokens.. DeallocateTokens(); - // Todo: How should this work? Activated by a command line switch? - if ( ! HasErrors ) + if ( errout.str().empty() ) std::cout << "No errors found\n"; } //--------------------------------------------------------------------------- @@ -278,19 +270,3 @@ static void CppCheck(const char FileName[]) - - - - - - - - - - - - - - - - diff --git a/tests.cpp b/tests.cpp index 7ffb6ec81..f1cdb5581 100644 --- a/tests.cpp +++ b/tests.cpp @@ -86,7 +86,6 @@ static void check(void (chk)(), if ( chk != CheckUnsignedDivision ) SimplifyTokenList(); - FunctionList.clear(); FillFunctionList(); // Check for buffer overruns..