Fix 10615: Crash in Token::linkAt (#3599)

This commit is contained in:
Paul Fultz II 2021-12-04 05:57:59 -06:00 committed by GitHub
parent bc31419da0
commit 29dbded4af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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;

View File

@ -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() {