Fix 10664: Crash in Token::linkAt (#3708)

* Fix 10664: Crash in Token::linkAt

* Format
This commit is contained in:
Paul Fultz II 2022-01-14 16:51:01 -06:00 committed by GitHub
parent 2b6a89e30e
commit 0b1cd8626d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -4554,7 +4554,8 @@ void Tokenizer::createLinks2()
}
} else {
type.pop();
if (Token::Match(token, "> %name%") && Token::Match(top1->tokAt(-2), "%op% %name% <") &&
if (Token::Match(token, "> %name%") && !token->next()->isKeyword() &&
Token::Match(top1->tokAt(-2), "%op% %name% <") &&
(templateTokens.empty() || top1 != templateTokens.top()))
continue;
Token::createMutualLinks(top1, token);

View File

@ -3375,6 +3375,19 @@ private:
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}
{
// #10664
const char code[] = "class C1 : public T1<D2<C2>const> {};\n";
errout.str("");
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< C2");
const Token* tok2 = Token::findsimplematch(tok1, "> const");
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}
}
void simplifyString() {