memset: using memset on struct/class that has std::string member variable. ticket: #1655
This commit is contained in:
parent
26152a9264
commit
db7ce1c13c
|
@ -712,6 +712,18 @@ void CheckClass::noMemset()
|
|||
type = tok->strAt(10);
|
||||
else if (Token::Match(tok, "%type% ( %var% , %var% , sizeof ( %type% ) )"))
|
||||
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
|
||||
if (type.empty())
|
||||
|
|
|
@ -2966,7 +2966,7 @@ private:
|
|||
" Fred fred;\n"
|
||||
" memset(&fred, 0, sizeof(fred));\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()
|
||||
|
|
Loading…
Reference in New Issue