Fix platform-dependent test result, formatting and crash in whole program analysis

This commit is contained in:
Alexander Mai 2015-06-28 17:54:48 +02:00
parent 4a47b8b3ae
commit 2c73518e29
10 changed files with 20 additions and 21 deletions

View File

@ -97,8 +97,9 @@ public:
return nullptr; return nullptr;
} }
virtual void analyseWholeProgram(const std::list<FileInfo*> &fileInfo, ErrorLogger &errorLogger) { virtual void analyseWholeProgram(const std::list<FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) {
(void)fileInfo; (void)fileInfo;
(void)settings;
(void)errorLogger; (void)errorLogger;
} }

View File

@ -1797,7 +1797,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
return fileInfo; return fileInfo;
} }
void CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger) void CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
{ {
// Merge all fileInfo // Merge all fileInfo
MyFileInfo all; MyFileInfo all;

View File

@ -212,7 +212,7 @@ public:
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const; Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
/** @brief Analyse all file infos for all TU */ /** @brief Analyse all file infos for all TU */
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger); void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger);
private: private:

View File

@ -1379,8 +1379,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
void CheckMemoryLeakInFunction::simplifycode(Token *tok) const void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
{ {
if (_tokenizer->isCPP()) if (_tokenizer->isCPP()) {
{
// Replace "throw" that is not in a try block with "return" // Replace "throw" that is not in a try block with "return"
int indentlevel = 0; int indentlevel = 0;
int trylevel = -1; int trylevel = -1;

View File

@ -57,7 +57,7 @@ void CheckNonReentrantFunctions::nonReentrantFunctions()
continue; continue;
// Check for "std" or global namespace, ignore other namespaces // 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; continue;
} }

View File

@ -51,7 +51,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
continue; continue;
// Don't care about templates // Don't care about templates
if (tokenizer.isCPP() && func->retDef->str() == "template") if (tokenizer.isCPP() && func->retDef->str() == "template")
continue; continue;
FunctionUsage &usage = _functions[func->name()]; FunctionUsage &usage = _functions[func->name()];
@ -216,7 +216,7 @@ void CheckUnusedFunctions::check(ErrorLogger * const errorLogger)
if (func.usedOtherFile || func.filename.empty()) if (func.usedOtherFile || func.filename.empty())
continue; continue;
if (it->first == "main" || 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 == "if" ||
(it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8]))) (it->first.compare(0, 8, "operator") == 0 && it->first.size() > 8 && !std::isalnum(it->first[8])))
continue; continue;
@ -268,5 +268,5 @@ Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, c
void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger) void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger)
{ {
(void)fileInfo; (void)fileInfo;
instance.check(&errorLogger); check(&errorLogger);
} }

View File

@ -690,7 +690,7 @@ void CppCheck::analyseWholeProgram()
{ {
// Analyse the tokens // Analyse the tokens
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
(*it)->analyseWholeProgram(fileInfo, *this); (*it)->analyseWholeProgram(fileInfo, _settings, *this);
} }
bool CppCheck::unusedFunctionCheckIsEnabled() const bool CppCheck::unusedFunctionCheckIsEnabled() const

View File

@ -9859,7 +9859,7 @@ namespace {
void Tokenizer::simplifyMicrosoftStringFunctions() void Tokenizer::simplifyMicrosoftStringFunctions()
{ {
// skip if not Windows // skip if not Windows
if (!_settings->isWindowsPlatform()) if (!_settings->isWindowsPlatform())
return; return;
const bool ansi = _settings->platformType == Settings::Win32A; const bool ansi = _settings->platformType == Settings::Win32A;
@ -9892,7 +9892,7 @@ void Tokenizer::simplifyMicrosoftStringFunctions()
void Tokenizer::simplifyBorland() void Tokenizer::simplifyBorland()
{ {
// skip if not Windows // skip if not Windows
if (!_settings->isWindowsPlatform()) if (!_settings->isWindowsPlatform())
return; return;
if (isC()) if (isC())
return; return;
@ -9909,8 +9909,7 @@ void Tokenizer::simplifyBorland()
tok = tok->link(); tok = tok->link();
if (!tok) if (!tok)
break; break;
} } else if (Token::Match(tok, "class %name% :|{")) {
else if (Token::Match(tok, "class %name% :|{")) {
while (tok && tok->str() != "{" && tok->str() != ";") while (tok && tok->str() != "{" && tok->str() != ";")
tok = tok->next(); tok = tok->next();
if (!tok) if (!tok)

View File

@ -672,7 +672,7 @@ private:
} }
} }
Tokenizer tokenizer; Tokenizer tokenizer;
CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this); CheckMemoryLeakInFunction checkMemoryLeak(&tokenizer, &settings, this);
checkMemoryLeak.simplifycode(tokens); checkMemoryLeak.simplifycode(tokens);

View File

@ -57,13 +57,13 @@ private:
TEST_CASE(ignore_declaration); // ignore declaration 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.. // Clear the error buffer..
errout.str(""); errout.str("");
Settings settings; Settings settings;
settings.addEnabled("style"); settings.addEnabled("style");
settings.platform(platform);
// Tokenize.. // Tokenize..
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
std::istringstream istr(code); std::istringstream istr(code);
@ -228,10 +228,10 @@ private:
check("int main() { }"); check("int main() { }");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("int _tmain() { }"); check("int _tmain() { }", Settings::Win32A);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("int WinMain() { }"); check("int WinMain() { }", Settings::Win32A);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
@ -334,8 +334,8 @@ private:
void multipleFiles() { void multipleFiles() {
Settings settings; Settings settings;
Tokenizer tokenizer(&settings, this); Tokenizer tokenizer(&settings, this);
CheckUnusedFunctions c(&tokenizer, &settings, nullptr); CheckUnusedFunctions c(&tokenizer, &settings, nullptr);
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");