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

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

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

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