Skip to content

Commit a294079

Browse files
Fix #15060 Nullptr dereference in exprDependsOnThis() (#8894)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 43425ee commit a294079

3 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9166,9 +9166,19 @@ 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), ")")) {
9173+
const Token* const prev = tok->linkAt(-1)->tokAt(-1);
9174+
if (!Token::Match(prev, "%name% (") || (!prev->isControlFlowKeyword() && prev->str() != "decltype")) {
9175+
if (prev && prev->isUpperCaseName())
9176+
unknownMacroError(prev);
9177+
else
9178+
syntaxError(tok);
9179+
}
9180+
}
9181+
}
91729182
if (Token::Match(tok, "& %comp%|&&|%oror%|&|%or%") && tok->strAt(1) != ">")
91739183
syntaxError(tok);
91749184
if (Token::Match(tok, "%comp%|&&|%oror%|&|%or% }") && tok->str() != ">")

‎test/testsymboldatabase.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3774,9 +3774,8 @@ class TestSymbolDatabase : public TestFixture {
37743774
}
37753775

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

37823781
void symboldatabase36() { // ticket #4892

‎test/testtokenize.cpp‎

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

7922+
ASSERT_THROW_INTERNAL(tokenizeAndStringify("namespace N {\n"
7923+
" struct C {\n"
7924+
" void f();\n"
7925+
" };\n"
7926+
" void C(abc)::f() {\n"
7927+
" X x;\n"
7928+
" N::Y([&] { x(); })->g();\n"
7929+
" }\n"
7930+
"}\n"), UNKNOWN_MACRO);
7931+
79227932
ASSERT_THROW_INTERNAL_EQUALS(tokenizeAndStringify("static void handle_toggle(void (*proc) PROTO_XT_CALLBACK_ARGS, int var) {}\n"), // #13198
79237933
UNKNOWN_MACRO,
79247934
"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)