#7109 segmentation fault (invalid code) in TokenList::createAst

This commit is contained in:
Alexander Mai 2015-11-08 15:09:39 +01:00
parent fc564d779e
commit 5318970f1e
1 changed files with 5 additions and 3 deletions

View File

@ -963,6 +963,8 @@ static Token * createAstAtToken(Token *tok, bool cpp)
break;
init1 = 0;
}
if (!tok2) // #7109 invalid code
return nullptr;
tok2 = tok2->next();
}
if (!tok2 || tok2->str() != ";") {
@ -1023,7 +1025,7 @@ static Token * createAstAtToken(Token *tok, bool cpp)
return tok1;
// Compile inner expressions inside inner ({..}) and lambda bodies
for (tok = tok1->next(); tok && tok != endToken; tok = tok ? tok->next() : NULL) {
for (tok = tok1->next(); tok && tok != endToken; tok = tok ? tok->next() : nullptr) {
if (tok->str() != "{")
continue;
@ -1041,11 +1043,11 @@ static Token * createAstAtToken(Token *tok, bool cpp)
break;
const Token * const endToken2 = tok->link();
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : NULL)
for (; tok && tok != endToken && tok != endToken2; tok = tok ? tok->next() : nullptr)
tok = createAstAtToken(tok, cpp);
}
return endToken ? endToken->previous() : NULL;
return endToken ? endToken->previous() : nullptr;
}
return tok;