#6738 Avoid segfault on garbage code in Tokenizer::simplifyTypedef()

This commit is contained in:
Alexander Mai 2015-06-02 19:07:26 +02:00
parent 7895f1c2bb
commit be3690920a
2 changed files with 8 additions and 3 deletions

View File

@ -878,13 +878,13 @@ void Tokenizer::simplifyTypedef()
// typedef ... (( ... type )( ... ));
// typedef ... ( * ( ... type )( ... ));
else if (tokOffset->str() == "(" && (
(Token::Match(tokOffset->link()->previous(), "%type% ) (") &&
(tokOffset->link() && Token::Match(tokOffset->link()->previous(), "%type% ) (") &&
Token::Match(tokOffset->link()->next()->link(), ") const|volatile|;")) ||
(Token::simpleMatch(tokOffset, "( (") &&
Token::Match(tokOffset->next()->link()->previous(), "%type% ) (") &&
tokOffset->next() && Token::Match(tokOffset->next()->link()->previous(), "%type% ) (") &&
Token::Match(tokOffset->next()->link()->next()->link(), ") const|volatile| ) ;|,")) ||
(Token::simpleMatch(tokOffset, "( * (") &&
Token::Match(tokOffset->linkAt(2)->previous(), "%type% ) (") &&
tokOffset->linkAt(2) && Token::Match(tokOffset->linkAt(2)->previous(), "%type% ) (") &&
Token::Match(tokOffset->linkAt(2)->next()->link(), ") const|volatile| ) ;|,")))) {
if (tokOffset->next()->str() == "(")
tokOffset = tokOffset->next();

View File

@ -100,6 +100,7 @@ private:
TEST_CASE(garbageCode59); // #6735
TEST_CASE(garbageCode60); // #6736
TEST_CASE(garbageCode61);
TEST_CASE(garbageCode62);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -565,6 +566,10 @@ private:
ASSERT_THROW(checkCode("{ (const U&) }; { }; { }; struct U : virtual public"), InternalError);
}
void garbageCode62() { // #6738
checkCode("(int arg2) { } { } typedef void (func_type) (int, int); typedef func_type&");
}
void garbageValueFlow() {
// #6089