Merge pull request #247 from simartin/ticket_5425

Ticket #5425: Avoid infinite recursion in checkMemsetType
This commit is contained in:
Daniel Marjamäki 2014-03-03 07:23:56 +01:00
commit de7e8b78cf
2 changed files with 20 additions and 2 deletions

View File

@ -1020,6 +1020,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
// don't warn if variable static or const, pointer or reference
if (!var->isStatic() && !var->isConst() && !var->isPointer() && !var->isReference()) {
const Token *tok1 = var->typeStartToken();
const Scope *typeScope = var->typeScope();
// check for std:: type
if (var->isStlType())
@ -1029,8 +1030,8 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
memsetError(tok, tok->str(), "'std::" + tok1->strAt(2) + "'", type->classDef->str());
// check for known type
else if (var->typeScope())
checkMemsetType(start, tok, var->typeScope(), allocation);
else if (typeScope && typeScope != type)
checkMemsetType(start, tok, typeScope, allocation);
}
}
}

View File

@ -80,6 +80,7 @@ private:
TEST_CASE(memsetOnStruct);
TEST_CASE(memsetVector);
TEST_CASE(memsetOnClass);
TEST_CASE(memsetOnInvalid); // Ticket #5425: Crash upon invalid
TEST_CASE(mallocOnClass);
TEST_CASE(this_subtraction); // warn about "this-x"
@ -2285,6 +2286,22 @@ private:
ASSERT_EQUALS("", errout.str());
}
void memsetOnInvalid() { // Ticket #5425
checkNoMemset("union ASFStreamHeader {\n"
" struct AVMPACKED {\n"
" union {\n"
" struct AVMPACKED {\n"
" int width;\n"
" } vid;\n"
" };\n"
" } hdr;\n"
"};"
"void parseHeader() {\n"
" ASFStreamHeader strhdr;\n"
" memset(&strhdr, 0, sizeof(strhdr));\n"
"}");
}
void memsetOnStruct() {
checkNoMemset("struct A\n"
"{\n"