Skip to content

Commit ee5cf0f

Browse files
Fix #11810 nullptr deref in compilePrecedence2() (cppcheck-opensource#5218)
1 parent 682bdd3 commit ee5cf0f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lib/tokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7121,7 +7121,7 @@ void Tokenizer::simplifyVarDecl(Token * tokBegin, const Token * const tokEnd, co
71217121
if (Token::Match(tok2, "{|(|["))
71227122
tok2 = tok2->link();
71237123

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

71277127
else if (std::strchr(";,", tok2->str()[0])) {

test/testtokenize.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,6 +3501,20 @@ class TestTokenizer : public TestFixture {
35013501
ASSERT_EQUALS(true, tok1->link() == tok2);
35023502
ASSERT_EQUALS(true, tok2->link() == tok1);
35033503
}
3504+
3505+
{ // #11810
3506+
const char code[] = "void f() {\n"
3507+
" auto g = [] <typename A, typename B> (A a, B&& b) { return a < b; };\n"
3508+
"}\n";
3509+
errout.str("");
3510+
Tokenizer tokenizer(&settings0, this);
3511+
std::istringstream istr(code);
3512+
ASSERT(tokenizer.tokenize(istr, "test.cpp"));
3513+
const Token* tok1 = Token::findsimplematch(tokenizer.tokens(), "< A");
3514+
const Token* tok2 = Token::findsimplematch(tok1, "> (");
3515+
ASSERT_EQUALS(true, tok1->link() == tok2);
3516+
ASSERT_EQUALS(true, tok2->link() == tok1);
3517+
}
35043518
}
35053519

35063520
void simplifyString() {

0 commit comments

Comments
 (0)