From 29dbded4af6797a6025da5c0ba128b0bfbd940e1 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sat, 4 Dec 2021 05:57:59 -0600 Subject: [PATCH] Fix 10615: Crash in Token::linkAt (#3599) --- lib/tokenize.cpp | 3 +-- test/testtokenize.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ca1a77b7a..a2067add6 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4462,8 +4462,7 @@ void Tokenizer::createLinks2() type.pop(); } type.pop(); - } else - token->link(nullptr); + } } else if (templateTokens.empty() && !isStruct && Token::Match(token, "%oror%|&&|;")) { if (Token::Match(token, "&& [,>]")) continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index d978ad3f2..222967d19 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -3335,6 +3335,19 @@ private: ASSERT_EQUALS(true, tok1->link() == tok2); ASSERT_EQUALS(true, tok2->link() == tok1); } + + { + // #10615 + const char code[] = "struct A : public B<__is_constructible()>{};\n"; + errout.str(""); + Tokenizer tokenizer(&settings0, this); + std::istringstream istr(code); + ASSERT(tokenizer.tokenize(istr, "test.cpp")); + const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< >"); + const Token* tok2 = Token::findsimplematch(tok1, "> { } >"); + ASSERT_EQUALS(true, tok1->link() == tok2); + ASSERT_EQUALS(true, tok2->link() == tok1); + } } void simplifyString() {