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

This commit is contained in:
Lucas Manuel Rodriguez 2013-08-30 22:03:16 -03:00
parent c26674dc97
commit 92b7280d13
2 changed files with 11 additions and 8 deletions

View File

@ -914,10 +914,6 @@ 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;
@ -942,8 +938,12 @@ void CheckClass::noMemset()
const Variable *var = arg1->variable(); const Variable *var = arg1->variable();
if (var && arg1->strAt(1) == ",") { if (var && arg1->strAt(1) == ",") {
if (var->isPointer()) if (var->isPointer()) {
derefs--; derefs--;
if (var->typeEndToken() && Token::Match(var->typeEndToken()->previous(), "* *")) // Check if it's a pointer to pointer
derefs--;
}
if (var->isArray()) if (var->isArray())
derefs -= (int)var->dimensions().size(); derefs -= (int)var->dimensions().size();

View File

@ -2406,16 +2406,19 @@ private:
" C* c1[10][10];\n" " C* c1[10][10];\n"
" C* c2[10];\n" " C* c2[10];\n"
" C c3[10][10];\n" " C c3[10][10];\n"
" C** c4 = new C*[10];\n"
" memset(**c1, 0, 10);\n" " memset(**c1, 0, 10);\n"
" memset(*c1, 0, 10);\n" " memset(*c1, 0, 10);\n"
" memset(*c2, 0, 10);\n" " memset(*c2, 0, 10);\n"
" memset(*c3, 0, 10);\n" " memset(*c3, 0, 10);\n"
" memset(*c4, 0, 10);\n"
" memset(c2, 0, 10);\n" " memset(c2, 0, 10);\n"
" memset(c3, 0, 10);\n" " memset(c3, 0, 10);\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:8]: (error) Using 'memset' on struct that contains a 'std::string'.\n" ASSERT_EQUALS("[test.cpp:9]: (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"
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str()); "[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() { void mallocOnClass() {