Fix segmentation fault when calling with --errorlist and add a testcase for it.
This commit is contained in:
parent
a8f566bfcd
commit
be598757a1
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
|
@ -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[]);
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue