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;
}
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)settings;
(void)errorLogger;
}

View File

@ -1797,7 +1797,7 @@ Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
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
MyFileInfo all;

View File

@ -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<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger);
private:

View File

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

View File

@ -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;
}

View File

@ -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<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger)
{
(void)fileInfo;
instance.check(&errorLogger);
check(&errorLogger);
}

View File

@ -690,7 +690,7 @@ void CppCheck::analyseWholeProgram()
{
// Analyse the tokens
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

View File

@ -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)

View File

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

View File

@ -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("");