Skip to content

Commit

Permalink
Fix #11810 nullptr deref in compilePrecedence2() (#5218)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 5, 2023
1 parent 682bdd3 commit ee5cf0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7121,7 +7121,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
if (Token::Match(tok2, "{|(|["))
tok2 = tok2->link();

else if (!isC() && tok2->str() == "<" && tok2->previous()->isName() && !tok2->previous()->varId())
else if (!isC() && tok2->str() == "<" && ((tok2->previous()->isName() && !tok2->previous()->varId()) || tok2->strAt(-1) == "]"))
tok2 = tok2->findClosingBracket();

else if (std::strchr(";,", tok2->str()[0])) {
Expand Down
14 changes: 14 additions & 0 deletions test/testtokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,20 @@ class TestTokenizer : public TestFixture {
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}

{ // #11810
const char code[] = "void f() {\n"
" auto g = [] <typename A, typename B> (A a, B&& b) { return a < b; };\n"
"}\n";
errout.str("");
Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code);
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< A");
const Token* tok2 = Token::findsimplematch(tok1, "> (");
ASSERT_EQUALS(true, tok1->link() == tok2);
ASSERT_EQUALS(true, tok2->link() == tok1);
}
}

void simplifyString() {
Expand Down

0 comments on commit ee5cf0f

Please sign in to comment.