diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index bf8b96cde..53a3dc8b4 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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(); diff --git a/test/testclass.cpp b/test/testclass.cpp index 195e5deca..b403aa124 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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() {