From c9ade332980720d7917cd4ba8c9eec669c82ea97 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 15 Sep 2022 20:20:49 +0200 Subject: [PATCH] Fix memsetClass FP (#4465) --- lib/checkclass.cpp | 2 +- test/testclass.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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