From d608bec414d90bf70e23019ff1c497350a950c55 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Fri, 23 Sep 2022 20:18:49 +0200 Subject: [PATCH] Fix FP with std::array (#4497) * Fix #1655 wrong usage of std::string in memcpy * Fix memsetClass FP * Fix #8619 FN memset on container containing structs with containers * Token::Match * Use AST * simpleMatch * Fix FP with std::array * simpleMatch --- lib/checkclass.cpp | 3 ++- test/testclass.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 207458b3f..52ff2b449 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1361,7 +1361,8 @@ void CheckClass::checkMemset() if (numIndirToVariableType == 1) type = var->typeScope(); - if (!type && !var->isPointer() && mSettings->library.detectContainerOrIterator(var->typeStartToken())) { + if (!type && !var->isPointer() && !Token::simpleMatch(var->typeStartToken(), "std :: array") && + mSettings->library.detectContainerOrIterator(var->typeStartToken())) { memsetError(tok, tok->str(), var->getTypeName(), {}, /*isContainer*/ true); } } diff --git a/test/testclass.cpp b/test/testclass.cpp index e0bf7916a..6967e685a 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -3146,6 +3146,12 @@ private: " f

(Dst, Src, 2);\n" "}\n", s); ASSERT_EQUALS("", errout.str()); + + checkNoMemset("void f() {\n" + " std::array a;\n" + " std::memset(&a, 0, 4);\n" + "}\n", s); + ASSERT_EQUALS("", errout.str()); } void memsetOnInvalid() { // Ticket #5425