errmsg: Added "Using 'memset' on class"

This commit is contained in:
Daniel Marjamäki 2009-01-10 17:51:03 +00:00
parent 7b10b0ff4d
commit 1fc5f5485f
4 changed files with 24 additions and 4 deletions

View File

@ -617,9 +617,7 @@ void CheckClass::noMemset()
const std::string pattern1(std::string("class ") + type);
if (Token::findmatch(_tokenizer->tokens(), pattern1.c_str()))
{
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str() << "' on class.";
_errorLogger->reportErr(ostr.str());
_errorLogger->reportErr(ErrorMessage::memsetClass(_tokenizer, tok, tok->str()));
continue;
}
@ -632,6 +630,7 @@ void CheckClass::noMemset()
if (Token::Match(tstruct, "std :: %type% %var% ;"))
{
_errorLogger->reportErr(ErrorMessage::memsetStruct(_tokenizer, tok, tok->str(), tstruct->strAt(2)));
std::ostringstream ostr;
ostr << _tokenizer->fileLine(tok) << ": Using '" << tok->str() << "' on struct that contains a 'std::" << tstruct->strAt(2) << "'";
_errorLogger->reportErr(ostr.str());

View File

@ -238,7 +238,8 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
// The 'memset' function can do dangerous things if used wrong.
// Important: The checking doesn't work on simplified tokens list.
CheckClass checkClass(&_tokenizer, _settings, this);
checkClass.noMemset();
if (ErrorMessage::memsetClass(_settings))
checkClass.noMemset();
// Coding style checks that must be run before the simplifyTokenList

View File

@ -57,6 +57,24 @@ public:
return s._checkCodingStyle;
}
static std::string memsetClass(const Tokenizer *tokenizer, const Token *Location, const std::string &funcname)
{
return msg1(tokenizer, Location) + "Using '" + funcname + "' on class";
}
static bool memsetClass(const Settings &s)
{
return true;
}
static std::string memsetStruct(const Tokenizer *tokenizer, const Token *Location, const std::string &funcname, const std::string &classname)
{
return msg1(tokenizer, Location) + "Using '" + funcname + "' on struct that contains a 'std::" + classname + "'";
}
static bool memsetStruct(const Settings &s)
{
return true;
}
static std::string memleak(const Tokenizer *tokenizer, const Token *Location, const std::string &varname)
{
return msg1(tokenizer, Location) + "Memory leak: " + varname + "";

View File

@ -57,6 +57,8 @@ int main()
err.push_back(Message("noConstructor", Message::STYLE, "The class '%1' has no constructor", "classname"));
err.push_back(Message("uninitVar", 0, "Uninitialized member variable '%1::%2'", "classname", "varname"));
err.push_back(Message("unusedPrivateFunction", Message::STYLE, "Unused private function '%1::%2'", "classname", "funcname"));
err.push_back(Message("memsetClass", 0, "Using '%1' on class", "funcname"));
err.push_back(Message("memsetStruct", 0, "Using '%1' on struct that contains a 'std::%2'", "funcname", "classname"));
// checkmemoryleak.cpp..
err.push_back(Message("memleak", 0, "Memory leak: %1", "varname"));