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
This commit is contained in:
chrchr-github 2022-09-23 20:18:49 +02:00 committed by GitHub
parent 0bb82b70d9
commit d608bec414
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -3146,6 +3146,12 @@ private:
" f<P>(Dst, Src, 2);\n"
"}\n", s);
ASSERT_EQUALS("", errout.str());
checkNoMemset("void f() {\n"
" std::array<char, 4> a;\n"
" std::memset(&a, 0, 4);\n"
"}\n", s);
ASSERT_EQUALS("", errout.str());
}
void memsetOnInvalid() { // Ticket #5425