diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 08e75aef738..7e4d4adc443 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1429,7 +1429,7 @@ void CheckClass::checkMemset() const std::set parsedTypes; checkMemsetType(scope, tok, type, false, parsedTypes); } - } else if (tok->variable() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) { + } else if (tok->variable() && tok->variable()->isPointer() && tok->variable()->typeScope() && Token::Match(tok, "%var% = %name% (")) { const Library::AllocFunc* alloc = mSettings->library.getAllocFuncInfo(tok->tokAt(2)); if (!alloc) alloc = mSettings->library.getReallocFuncInfo(tok->tokAt(2)); diff --git a/test/testclass.cpp b/test/testclass.cpp index 6c26bb24add..5938170a1f5 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3598,6 +3598,15 @@ class TestClass : public TestFixture { " AutoCloseFD fd = open(\"abc\", O_RDONLY | O_CLOEXEC);\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkNoMemset("struct C {\n" // #12313 + " char* p;\n" + " C(char* ptr) : p(ptr) {}\n" + "};\n" + "void f() {\n" + " C c = strdup(\"abc\");\n" + "}"); + ASSERT_EQUALS("", errout.str()); } #define checkThisSubtraction(code) checkThisSubtraction_(code, __FILE__, __LINE__)