template simplifier: fix some crashes (#1772)

Fix some crashes caused by the template simplifier generating bad code
for some instantiations.

Sorry but there are no tests because I was unable to get C-Reduce to
create examples that were not garbage code.
This commit is contained in:
IOBYTE 2019-04-01 02:04:47 -04:00 committed by Daniel Marjamäki
parent 0368648aff
commit 165cce5dcc
1 changed files with 7 additions and 1 deletions

View File

@ -1479,6 +1479,10 @@ void TemplateSimplifier::expandTemplate(
dst->previous()->isLong(start->isLong());
}
}
if (!start)
continue;
if (start->link()) {
if (Token::Match(start, "[|{|(")) {
links[start->link()] = dst->previous();
@ -2342,6 +2346,8 @@ bool TemplateSimplifier::matchSpecialization(
const Token *instToken = templateInstantiationNameToken->tokAt(2);
const Token *declToken = (*it)->tokAt(2);
const Token * const endToken = (*it)->next()->findClosingBracket();
if (!endToken)
continue;
while (declToken != endToken) {
if (declToken->str() != instToken->str()) {
int nr = 0;
@ -2355,7 +2361,7 @@ bool TemplateSimplifier::matchSpecialization(
instToken = instToken->next();
}
if (declToken == endToken && instToken->str() == ">") {
if (declToken && instToken && declToken == endToken && instToken->str() == ">") {
// specialization matches.
return templateDeclarationNameToken == *it;
}