memset: using memset on struct/class that has std::string member variable. ticket: #1655

This commit is contained in:
Chuck Larson 2011-02-24 18:38:45 +01:00 committed by Daniel Marjamäki
parent 26152a9264
commit db7ce1c13c
2 changed files with 13 additions and 1 deletions

View File

@ -712,6 +712,18 @@ void CheckClass::noMemset()
type = tok->strAt(10); type = tok->strAt(10);
else if (Token::Match(tok, "%type% ( %var% , %var% , sizeof ( %type% ) )")) else if (Token::Match(tok, "%type% ( %var% , %var% , sizeof ( %type% ) )"))
type = tok->strAt(8); type = tok->strAt(8);
else if (Token::Match(tok, "memset ( & %var% , %num% , sizeof ( %var% ) )"))
{
unsigned int varid = tok->tokAt(3)->varId();
for (const Token *lookback = tok->previous(); lookback; lookback = lookback->previous())
{
if (Token::Match(lookback, "%type% %varid%",varid))
{
type = lookback->str();
break;
}
}
}
// No type defined => The tokens didn't match // No type defined => The tokens didn't match
if (type.empty()) if (type.empty())

View File

@ -2966,7 +2966,7 @@ private:
" Fred fred;\n" " Fred fred;\n"
" memset(&fred, 0, sizeof(fred));\n" " memset(&fred, 0, sizeof(fred));\n"
"}\n"); "}\n");
TODO_ASSERT_EQUALS("error", "", errout.str()); ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
} }
void memsetVector() void memsetVector()