From db274e830865c99be1a4d0709b16018f9951d140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 10 Feb 2018 15:34:49 +0100 Subject: [PATCH] Fix testrunner in cygwin --- cli/cppcheckexecutor.cpp | 3 +++ lib/checkunusedfunctions.cpp | 6 +----- lib/checkunusedfunctions.h | 7 ++++++- lib/cppcheck.cpp | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index ffba26ce1..3653d940f 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -33,6 +33,7 @@ #include "suppressions.h" #include "threadexecutor.h" #include "utils.h" +#include "checkunusedfunctions.h" #include #include @@ -179,6 +180,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) Preprocessor::missingIncludeFlag = false; Preprocessor::missingSystemIncludeFlag = false; + CheckUnusedFunctions::clear(); + CppCheck cppCheck(*this, true); const Settings& settings = cppCheck.settings(); diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 030487c86..cbcd70d2e 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -47,14 +47,12 @@ static const struct CWE CWE561(561U); // Dead Code // FUNCTION USAGE - Check for unused functions etc //--------------------------------------------------------------------------- -void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings, bool clear) +void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings) { const bool doMarkup = settings->library.markupFile(FileName); const SymbolDatabase* symbolDatabase = tokenizer.getSymbolDatabase(); // Function declarations.. - if (clear) - _functionDecl.clear(); for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); i++) { const Scope* scope = symbolDatabase->functionScopes[i]; const Function* func = scope->function; @@ -88,8 +86,6 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi } // Function usage.. - if (clear) - _functionCalls.clear(); for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) { // parsing of library code to find called functions diff --git a/lib/checkunusedfunctions.h b/lib/checkunusedfunctions.h index 20f2d88d6..ae41c8df4 100644 --- a/lib/checkunusedfunctions.h +++ b/lib/checkunusedfunctions.h @@ -50,10 +50,15 @@ public: : Check(myName(), tokenizer, settings, errorLogger) { } + static void clear() { + instance._functions.clear(); + instance._functionCalls.clear(); + } + // Parse current tokens and determine.. // * Check what functions are used // * What functions are declared - void parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings, bool clear=true); + void parseTokens(const Tokenizer &tokenizer, const char FileName[], const Settings *settings); // Return true if an error is reported. bool check(ErrorLogger * const errorLogger, const Settings& settings); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 7f2153c35..053d26e17 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -399,7 +399,7 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin // Analyze info.. if (!_settings.buildDir.empty()) - checkUnusedFunctions.parseTokens(_tokenizer, filename.c_str(), &_settings, false); + checkUnusedFunctions.parseTokens(_tokenizer, filename.c_str(), &_settings); // simplify more if required, skip rest of iteration if failed if (_simplify) {