diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 63accecf9..bf8b96cde 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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% ) )")) diff --git a/test/testclass.cpp b/test/testclass.cpp index bc9f4af2f..195e5deca 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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() {