Fixed #4995 (False positive - Using 'memset' on class that contains a virtual method)

This commit is contained in:
Lucas Manuel Rodriguez 2013-08-30 08:46:33 -03:00
parent 4a1d1ce1a1
commit c26674dc97
2 changed files with 16 additions and 0 deletions

View File

@ -914,6 +914,11 @@ void CheckClass::noMemset()
// 3 arguments.
continue;
// Check if it's not a pointer to pointer
if (arg1->variable() && arg1->variable()->typeEndToken() &&
Token::Match(arg1->variable()->typeEndToken()->previous(), "* *"))
continue;
const Token *typeTok = 0;
const Scope *type = 0;
if (Token::Match(arg3, "sizeof ( %type% ) )"))

View File

@ -2219,6 +2219,17 @@ private:
" memset(&fred, 0, sizeof(fred));\n"
"}");
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
checkNoMemset("class A {\n"
" virtual ~A() { }\n"
" std::string s;\n"
"};\n"
"int f() {\n"
" const int N = 10;\n"
" A** arr = new A*[N];\n"
" memset(arr, 0, N * sizeof(A*));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void memsetOnStruct() {