CheckClass::checkMemsetType(): Skip arrays of pointers (#7456)

This commit is contained in:
PKEuS 2016-05-04 13:38:36 +02:00
parent 21b51dd235
commit 17ccb0fbe6
2 changed files with 16 additions and 2 deletions

View File

@ -1109,8 +1109,8 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
memsetErrorReference(tok, tok->str(), type->classDef->str());
continue;
}
// don't warn if variable static or const, pointer or reference
if (!var->isStatic() && !var->isConst() && !var->isPointer()) {
// don't warn if variable static or const, pointer or array of pointers
if (!var->isStatic() && !var->isConst() && !var->isPointer() && (!var->isArray() || var->typeEndToken()->str() != "*")) {
const Token *tok1 = var->typeStartToken();
const Scope *typeScope = var->typeScope();

View File

@ -2400,6 +2400,20 @@ private:
" memset(&a, 0, sizeof(a)); \n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Using 'memset' on class that contains a reference.\n", errout.str());
// #7456
checkNoMemset("struct A {\n"
" A() {}\n"
" virtual ~A() {}\n"
"};\n"
"struct B {\n"
" A* arr[4];\n"
"};\n"
"void func() {\n"
" B b[4];\n"
" memset(b, 0, sizeof(b));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void memsetOnInvalid() { // Ticket #5425