Fixed #1287 (Use of memset on struct - std template types not handled)
This commit is contained in:
parent
0ba665d77f
commit
9943262da0
|
@ -745,16 +745,8 @@ void CheckClass::noMemset()
|
|||
if (!(type && type[0]))
|
||||
continue;
|
||||
|
||||
// Warn if type is a class..
|
||||
const std::string pattern1(std::string("class ") + type);
|
||||
if (Token::findmatch(_tokenizer->tokens(), pattern1.c_str()))
|
||||
{
|
||||
memsetClassError(tok, tok->str());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Warn if type is a struct that contains any std::*
|
||||
const std::string pattern2(std::string("struct ") + type + " {");
|
||||
// Warn if type is a class or struct that contains any std::* variables
|
||||
const std::string pattern2(std::string("struct|class ") + type + " {");
|
||||
for (const Token *tstruct = Token::findmatch(_tokenizer->tokens(), pattern2.c_str()); tstruct; tstruct = tstruct->next())
|
||||
{
|
||||
if (tstruct->str() == "}")
|
||||
|
@ -765,6 +757,12 @@ void CheckClass::noMemset()
|
|||
memsetStructError(tok, tok->str(), tstruct->strAt(2));
|
||||
break;
|
||||
}
|
||||
|
||||
if (Token::Match(tstruct, "std :: %type% < %type% > %var% ;"))
|
||||
{
|
||||
memsetStructError(tok, tok->str(), tstruct->strAt(2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1436,18 +1436,18 @@ private:
|
|||
"};\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" A fail;\n"
|
||||
" memset(&fail, 0, sizeof(A));\n"
|
||||
" A a;\n"
|
||||
" memset(&a, 0, sizeof(A));\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on class\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNoMemset("struct A\n"
|
||||
"{\n"
|
||||
"};\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" struct A fail;\n"
|
||||
" memset(&fail, 0, sizeof(A));\n"
|
||||
" struct A a;\n"
|
||||
" memset(&a, 0, sizeof(A));\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
@ -1481,6 +1481,19 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
|
||||
}
|
||||
|
||||
void memsetVector()
|
||||
{
|
||||
checkNoMemset("struct A\n"
|
||||
"{ std::vector<int> ints; }\n"
|
||||
"\n"
|
||||
"void f()\n"
|
||||
"{\n"
|
||||
" A a;\n"
|
||||
" memset(a, 0, sizeof(A));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:7]: (error) Using 'memset' on struct that contains a 'std::vector'\n", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void checkThisSubtraction(const char code[])
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue