Fix crash in constPointer() (#4945)

This commit is contained in:
chrchr-github 2023-04-09 16:38:09 +02:00 committed by GitHub
parent 7726a5b5b3
commit 63151f3291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -1478,7 +1478,7 @@ void CheckOther::checkConstVariable()
else
opTok = opTok->astOperand2();
}
if (opTok->valueType() && var->valueType() && opTok->valueType()->isConst(var->valueType()->pointer))
if (opTok && opTok->valueType() && var->valueType() && opTok->valueType()->isConst(var->valueType()->pointer))
continue;
} else if (const Token* ftok = getTokenArgumentFunction(tok, argn)) {
bool inconclusive{};

View File

@ -3486,6 +3486,12 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str()); // don't crash
check("void f(int& i) {\n"
" int& r = i;\n"
" if (!&r) {}\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'r' can be declared as reference to const\n", "", errout.str()); // don't crash
check("class C;\n" // #11646
"void g(const C* const p);\n"
"void f(C* c) {\n"