Fix segmentation fault when calling with --errorlist and add a testcase for it.

This commit is contained in:
Reijo Tomperi 2010-04-03 22:53:06 +03:00
parent a8f566bfcd
commit be598757a1
4 changed files with 34 additions and 14 deletions

View File

@ -2629,7 +2629,10 @@ void CheckOther::zerodivError(const Token *tok)
void CheckOther::mathfunctionCallError(const Token *tok) void CheckOther::mathfunctionCallError(const Token *tok)
{ {
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result"); if (tok)
reportError(tok, Severity::error, "wrongmathcall", "Passing value " + tok->tokAt(2)->str() + " to " + tok->str() + "() leads to undefined result");
else
reportError(tok, Severity::error, "wrongmathcall", "Passing value " " to " "() leads to undefined result");
} }
void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement) void CheckOther::postIncrementError(const Token *tok, const std::string &var_name, const bool isIncrement)

View File

@ -320,19 +320,7 @@ void CppCheck::parseFromArgs(int argc, const char* const argv[])
// print all possible error messages.. // print all possible error messages..
else if (strcmp(argv[i], "--errorlist") == 0) else if (strcmp(argv[i], "--errorlist") == 0)
{ {
// call all "getErrorMessages" in all registered Check classes getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->getErrorMessages();
}
Tokenizer tokenizer(&_settings, 0);
tokenizer.getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
return;
} }
// documentation.. // documentation..
@ -674,3 +662,18 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
{ {
} }
void CppCheck::getErrorMessages()
{
// call all "getErrorMessages" in all registered Check classes
std::cout << ErrorLogger::ErrorMessage::getXMLHeader();
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
{
(*it)->getErrorMessages();
}
Tokenizer tokenizer(&_settings, 0);
tokenizer.getErrorMessages();
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
}

View File

@ -124,6 +124,12 @@ public:
_settings.terminate(); _settings.terminate();
} }
/**
* @brief Call all "getErrorMessages" in all registered Check classes.
* Also print out xml header and footer.
*/
void getErrorMessages();
private: private:
void checkFile(const std::string &code, const char FileName[]); void checkFile(const std::string &code, const char FileName[]);

View File

@ -54,6 +54,7 @@ private:
TEST_CASE(include); TEST_CASE(include);
TEST_CASE(templateFormat); TEST_CASE(templateFormat);
TEST_CASE(getErrorMessages);
} }
void linenumbers() void linenumbers()
@ -120,6 +121,13 @@ private:
ASSERT_EQUALS("[some/{file}file.cpp:10]: (testSeverity) long testMessage", errmsg.toText()); ASSERT_EQUALS("[some/{file}file.cpp:10]: (testSeverity) long testMessage", errmsg.toText());
ASSERT_EQUALS("testId-some/{file}file.cpp,testSeverity.10?{long testMessage}", errmsg.toText("{id}-{file},{severity}.{line}?{{message}}")); ASSERT_EQUALS("testId-some/{file}file.cpp,testSeverity.10?{long testMessage}", errmsg.toText("{id}-{file},{severity}.{line}?{{message}}"));
} }
void getErrorMessages()
{
errout.str("");
CppCheck cppCheck(*this);
cppCheck.getErrorMessages();
}
}; };
REGISTER_TEST(TestCppcheck) REGISTER_TEST(TestCppcheck)