Fixed #7119 (Cppcheck hangs with 100% CPU load in Tokenizer::copyTokens (invalidcode))

This commit is contained in:
Daniel Marjamäki 2015-11-29 14:56:15 +01:00
parent 4eaf585dd2
commit 8a9e068129
2 changed files with 10 additions and 0 deletions

View File

@ -1237,6 +1237,8 @@ void Tokenizer::simplifyTypedef()
bool inOperator = false;
bool inSizeof = false;
const bool sameStartEnd = (typeStart == typeEnd);
// check for derived class: class A : some_typedef {
const bool isDerived = Token::Match(tok2->previous(), "public|protected|private %type% {|,");
@ -1274,6 +1276,9 @@ void Tokenizer::simplifyTypedef()
if (typeStart->str() == "struct" && Token::Match(tok2, "%name% ::"))
typeStart = typeStart->next();
if (sameStartEnd)
typeEnd = typeStart;
// start substituting at the typedef name by replacing it with the type
tok2->str(typeStart->str());

View File

@ -207,6 +207,7 @@ private:
TEST_CASE(garbageCode156); // #7120
TEST_CASE(garbageCode157); // #7131
TEST_CASE(garbageCode158); // #3238
TEST_CASE(garbageCode159); // #7119
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -1246,6 +1247,10 @@ private:
checkCode("__FBSDID(\"...\");\n");
}
void garbageCode159() { // #7119
checkCode("({}typedef typename x;typename x!){({{}()})}"); // dont hang
}
void garbageValueFlow() {
// #6089