diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index cce0e0fc2..a1a133008 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1354,7 +1354,7 @@ void CheckClass::checkMemset() if (numIndirToVariableType == 1) type = var->typeScope(); - if (!type && mSettings->library.detectContainerOrIterator(var->typeStartToken())) { + if (!type && !var->isPointer() && mSettings->library.detectContainerOrIterator(var->typeStartToken())) { memsetError(tok, tok->str(), var->getTypeName(), {}, /*isContainer*/ true); } } diff --git a/test/testclass.cpp b/test/testclass.cpp index 683739cc1..ca950e27b 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3119,6 +3119,18 @@ private: " memcpy(&s, c, strlen(c) + 1);\n" "}\n", s); ASSERT_EQUALS("[test.cpp:4]: (error) Using 'memcpy' on std::string.\n", errout.str()); + + checkNoMemset("template \n" + " void f(T* dst, const T* src, int N) {\n" + " std::memcpy(dst, src, N * sizeof(T));\n" + "}\n" + "void g() {\n" + " typedef std::vector* P;\n" + " P Src[2]{};\n" + " P Dst[2];\n" + " f

(Dst, Src, 2);\n" + "}\n", s); + ASSERT_EQUALS("", errout.str()); } void memsetOnInvalid() { // Ticket #5425