Fixed #4995 (False positive - Using 'memset' on class that contains a virtual method)
This commit is contained in:
parent
4a1d1ce1a1
commit
c26674dc97
|
@ -914,6 +914,11 @@ void CheckClass::noMemset()
|
||||||
// 3 arguments.
|
// 3 arguments.
|
||||||
continue;
|
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 Token *typeTok = 0;
|
||||||
const Scope *type = 0;
|
const Scope *type = 0;
|
||||||
if (Token::Match(arg3, "sizeof ( %type% ) )"))
|
if (Token::Match(arg3, "sizeof ( %type% ) )"))
|
||||||
|
|
|
@ -2219,6 +2219,17 @@ private:
|
||||||
" memset(&fred, 0, sizeof(fred));\n"
|
" memset(&fred, 0, sizeof(fred));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str());
|
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() {
|
void memsetOnStruct() {
|
||||||
|
|
Loading…
Reference in New Issue