Fixed #4995 (False positive - Using 'memset' on class that contains a virtual method) - Better fix
This commit is contained in:
parent
c26674dc97
commit
92b7280d13
|
@ -914,10 +914,6 @@ 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;
|
||||
|
@ -942,8 +938,12 @@ void CheckClass::noMemset()
|
|||
|
||||
const Variable *var = arg1->variable();
|
||||
if (var && arg1->strAt(1) == ",") {
|
||||
if (var->isPointer())
|
||||
if (var->isPointer()) {
|
||||
derefs--;
|
||||
if (var->typeEndToken() && Token::Match(var->typeEndToken()->previous(), "* *")) // Check if it's a pointer to pointer
|
||||
derefs--;
|
||||
}
|
||||
|
||||
if (var->isArray())
|
||||
derefs -= (int)var->dimensions().size();
|
||||
|
||||
|
|
|
@ -2406,16 +2406,19 @@ private:
|
|||
" C* c1[10][10];\n"
|
||||
" C* c2[10];\n"
|
||||
" C c3[10][10];\n"
|
||||
" C** c4 = new C*[10];\n"
|
||||
" memset(**c1, 0, 10);\n"
|
||||
" memset(*c1, 0, 10);\n"
|
||||
" memset(*c2, 0, 10);\n"
|
||||
" memset(*c3, 0, 10);\n"
|
||||
" memset(*c4, 0, 10);\n"
|
||||
" memset(c2, 0, 10);\n"
|
||||
" memset(c3, 0, 10);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||
"[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:9]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||
"[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||
"[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||
}
|
||||
|
||||
void mallocOnClass() {
|
||||
|
|
Loading…
Reference in New Issue