From 2c73518e290dde79c2b936f7a095ee5ecb32b1a1 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sun, 28 Jun 2015 17:54:48 +0200 Subject: [PATCH] Fix platform-dependent test result, formatting and crash in whole program analysis --- lib/check.h | 3 ++- lib/checkbufferoverrun.cpp | 2 +- lib/checkbufferoverrun.h | 2 +- lib/checkmemoryleak.cpp | 3 +-- lib/checknonreentrantfunctions.cpp | 2 +- lib/checkunusedfunctions.cpp | 6 +++--- lib/cppcheck.cpp | 2 +- lib/tokenize.cpp | 7 +++---- test/testmemleak.cpp | 2 +- test/testunusedfunctions.cpp | 12 ++++++------ 10 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/check.h b/lib/check.h index 2189e4264..34a06c211 100644 --- a/lib/check.h +++ b/lib/check.h @@ -97,8 +97,9 @@ public: return nullptr; } - virtual void analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger) { + virtual void analyseWholeProgram(const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) { (void)fileInfo; + (void)settings; (void)errorLogger; } diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 535609f65..52a5cd2c0 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -1797,7 +1797,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con return fileInfo; } -void CheckBufferOverrun::analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger) +void CheckBufferOverrun::analyseWholeProgram(const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger) { // Merge all fileInfo MyFileInfo all; diff --git a/lib/checkbufferoverrun.h b/lib/checkbufferoverrun.h index 20e0ae250..9470f6c64 100644 --- a/lib/checkbufferoverrun.h +++ b/lib/checkbufferoverrun.h @@ -212,7 +212,7 @@ public: Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const; /** @brief Analyse all file infos for all TU */ - void analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger); + void analyseWholeProgram(const std::list &fileInfo, const Settings& settings, ErrorLogger &errorLogger); private: diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 76c99634f..f495bf857 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1379,8 +1379,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listisCPP()) - { + if (_tokenizer->isCPP()) { // Replace "throw" that is not in a try block with "return" int indentlevel = 0; int trylevel = -1; diff --git a/lib/checknonreentrantfunctions.cpp b/lib/checknonreentrantfunctions.cpp index b5f154015..ad423bced 100644 --- a/lib/checknonreentrantfunctions.cpp +++ b/lib/checknonreentrantfunctions.cpp @@ -57,7 +57,7 @@ void CheckNonReentrantFunctions::nonReentrantFunctions() continue; // Check for "std" or global namespace, ignore other namespaces - if (_tokenizer->isCPP() && prev->str() == "::" && prev->previous() && prev->previous()->str() != "std" && prev->previous()->isName()) + if (_tokenizer->isCPP() && prev->str() == "::" && prev->previous() && prev->previous()->str() != "std" && prev->previous()->isName()) continue; } diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 7ddd9339d..6122730e1 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -51,7 +51,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi continue; // Don't care about templates - if (tokenizer.isCPP() && func->retDef->str() == "template") + if (tokenizer.isCPP() && func->retDef->str() == "template") continue; FunctionUsage &usage = _functions[func->name()]; @@ -216,7 +216,7 @@ void CheckUnusedFunctions::check(ErrorLogger * const errorLogger) if (func.usedOtherFile || func.filename.empty()) continue; if (it->first == "main" || - (_settings->isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) || + (_settings->isWindowsPlatform() && (it->first == "WinMain" || it->first == "_tmain")) || it->first == "if" || (it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8]))) continue; @@ -268,5 +268,5 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c void CheckUnusedFunctions::analyseWholeProgram(const std::list &fileInfo, ErrorLogger &errorLogger) { (void)fileInfo; - instance.check(&errorLogger); + check(&errorLogger); } diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 3043b597b..1916730bf 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -690,7 +690,7 @@ void CppCheck::analyseWholeProgram() { // Analyse the tokens for (std::list::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) - (*it)->analyseWholeProgram(fileInfo, *this); + (*it)->analyseWholeProgram(fileInfo, _settings, *this); } bool CppCheck::unusedFunctionCheckIsEnabled() const diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ee595239f..49a7b8942 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9859,7 +9859,7 @@ namespace { void Tokenizer::simplifyMicrosoftStringFunctions() { // skip if not Windows - if (!_settings->isWindowsPlatform()) + if (!_settings->isWindowsPlatform()) return; const bool ansi = _settings->platformType == Settings::Win32A; @@ -9892,7 +9892,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions() void Tokenizer::simplifyBorland() { // skip if not Windows - if (!_settings->isWindowsPlatform()) + if (!_settings->isWindowsPlatform()) return; if (isC()) return; @@ -9909,8 +9909,7 @@ void Tokenizer::simplifyBorland() tok = tok->link(); if (!tok) break; - } - else if (Token::Match(tok, "class %name% :|{")) { + } else if (Token::Match(tok, "class %name% :|{")) { while (tok && tok->str() != "{" && tok->str() != ";") tok = tok->next(); if (!tok) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 9d2265a8f..3474b6052 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -672,7 +672,7 @@ private: } } - Tokenizer tokenizer; + Tokenizer tokenizer; CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); checkMemoryLeak.simplifycode(tokens); diff --git a/test/testunusedfunctions.cpp b/test/testunusedfunctions.cpp index 4dc2a1096..e12e8482e 100644 --- a/test/testunusedfunctions.cpp +++ b/test/testunusedfunctions.cpp @@ -57,13 +57,13 @@ private: TEST_CASE(ignore_declaration); // ignore declaration } - void check(const char code[]) { + void check(const char code[], Settings::PlatformType platform = Settings::Unspecified) { // Clear the error buffer.. errout.str(""); Settings settings; settings.addEnabled("style"); - + settings.platform(platform); // Tokenize.. Tokenizer tokenizer(&settings, this); std::istringstream istr(code); @@ -228,10 +228,10 @@ private: check("int main() { }"); ASSERT_EQUALS("", errout.str()); - check("int _tmain() { }"); + check("int _tmain() { }", Settings::Win32A); ASSERT_EQUALS("", errout.str()); - check("int WinMain() { }"); + check("int WinMain() { }", Settings::Win32A); ASSERT_EQUALS("", errout.str()); } @@ -334,8 +334,8 @@ private: void multipleFiles() { Settings settings; - Tokenizer tokenizer(&settings, this); - CheckUnusedFunctions c(&tokenizer, &settings, nullptr); + Tokenizer tokenizer(&settings, this); + CheckUnusedFunctions c(&tokenizer, &settings, nullptr); // Clear the error buffer.. errout.str("");