Skip to content

Commit 638cc97

Browse files
committed
Fix #15060 Nullptr dereference in exprDependsOnThis()
1 parent f1c0820 commit 638cc97

4 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎lib/astutils.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,8 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
11591159
}
11601160
if (expr->isOperatorKeyword() && !Token::simpleMatch(expr->next()->astParent(), "."))
11611161
return true;
1162-
if (expr->variable() && expr->variable()->isArgument() && !expr->variable()->type() && expr->variable()->scope()->function && expr->variable()->scope()->function->templateDef)
1163-
return true;
1162+
// if (expr->variable() && expr->variable()->isArgument() && !expr->variable()->type() && expr->variable()->scope()->function && expr->variable()->scope()->function->templateDef)
1163+
// return true;
11641164
}
11651165
if (onVar && expr->variable()) {
11661166
const Variable* var = expr->variable();

‎lib/tokenize.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9166,9 +9166,16 @@ void Tokenizer::findGarbageCode() const
91669166
syntaxError(tok);
91679167
if (Token::Match(tok, "==|!=|<=|>= %comp%") && tok->strAt(-1) != "operator")
91689168
syntaxError(tok, tok->str() + " " + tok->strAt(1));
9169-
if (Token::simpleMatch(tok, "::") && (!Token::Match(tok->next(), "%name%|*|~") ||
9170-
(tok->next()->isKeyword() && !Token::Match(tok->next(), "new|delete|operator"))))
9171-
syntaxError(tok);
9169+
if (Token::simpleMatch(tok, "::")) {
9170+
if (!Token::Match(tok->next(), "%name%|*|~") || (tok->next()->isKeyword() && !Token::Match(tok->next(), "new|delete|operator")))
9171+
syntaxError(tok);
9172+
if (Token::simpleMatch(tok->tokAt(-1), ")") && !Token::simpleMatch(tok->linkAt(-1)->tokAt(-1), "decltype (")) {
9173+
if (tok->linkAt(-1)->tokAt(-1) && tok->linkAt(-1)->tokAt(-1)->isUpperCaseName())
9174+
unknownMacroError(tok);
9175+
else
9176+
syntaxError(tok);
9177+
}
9178+
}
91729179
if (Token::Match(tok, "& %comp%|&&|%oror%|&|%or%") && tok->strAt(1) != ">")
91739180
syntaxError(tok);
91749181
if (Token::Match(tok, "%comp%|&&|%oror%|&|%or% }") && tok->str() != ">")

‎test/testsymboldatabase.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3773,9 +3773,7 @@ class TestSymbolDatabase : public TestFixture {
37733773
}
37743774

37753775
void symboldatabase35() { // ticket #4806 and #4841
3776-
check("class FragmentQueue : public CL_NS(util)::PriorityQueue<CL_NS(util)::Deletor::Object<TextFragment> >\n"
3777-
"{};\n");
3778-
ASSERT_EQUALS("", errout_str());
3776+
ASSERT_THROW_INTERNAL(check("class FragmentQueue : public CL_NS(util)::PriorityQueue<CL_NS(util)::Deletor::Object<TextFragment> >\n"), UNKNOWN_MACRO);
37793777
}
37803778

37813779
void symboldatabase36() { // ticket #4892

‎test/testtokenize.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7910,6 +7910,16 @@ class TestTokenizer : public TestFixture {
79107910
" return std::string{ g() + \"abc\" MACRO \"def\" };\n"
79117911
"}\n"), UNKNOWN_MACRO);
79127912

7913+
ASSERT_THROW_INTERNAL(tokenizeAndStringify("namespace N {\n"
7914+
" struct C {\n"
7915+
" void f();\n"
7916+
" };\n"
7917+
" void C(abc)::f() {\n"
7918+
" X x;\n"
7919+
" N::Y([&] { x(); })->g();\n"
7920+
" }\n"
7921+
"}\n"), UNKNOWN_MACRO);
7922+
79137923
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("static void handle_toggle(void (*proc) PROTO_XT_CALLBACK_ARGS, int var) {}\n"), // #13198
79147924
UNKNOWN_MACRO,
79157925
"There is an unknown macro here somewhere. Configuration is required. If PROTO_XT_CALLBACK_ARGS is a macro then please configure it.");

0 commit comments

Comments
 (0)