Fix memsetClass FP (#4465)

This commit is contained in:
chrchr-github 2022-09-15 20:20:49 +02:00 committed by GitHub
parent f1aa9eb48f
commit c9ade33298
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -1354,7 +1354,7 @@ void CheckClass::checkMemset()
if (numIndirToVariableType == 1) if (numIndirToVariableType == 1)
type = var->typeScope(); 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); memsetError(tok, tok->str(), var->getTypeName(), {}, /*isContainer*/ true);
} }
} }

View File

@ -3119,6 +3119,18 @@ private:
" memcpy(&s, c, strlen(c) + 1);\n" " memcpy(&s, c, strlen(c) + 1);\n"
"}\n", s); "}\n", s);
ASSERT_EQUALS("[test.cpp:4]: (error) Using 'memcpy' on std::string.\n", errout.str()); ASSERT_EQUALS("[test.cpp:4]: (error) Using 'memcpy' on std::string.\n", errout.str());
checkNoMemset("template <typename T>\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<int>* P;\n"
" P Src[2]{};\n"
" P Dst[2];\n"
" f<P>(Dst, Src, 2);\n"
"}\n", s);
ASSERT_EQUALS("", errout.str());
} }
void memsetOnInvalid() { // Ticket #5425 void memsetOnInvalid() { // Ticket #5425