Fix #10758 Crash in CheckClass::checkConstFunc() (#3740)

This commit is contained in:
chrchr-github 2022-01-24 21:50:01 +01:00 committed by GitHub
parent 8179226b18
commit d64dadcd31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -2169,7 +2169,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool&
if (var && var->isStlType(stl_containers_not_const))
return false;
const Token* assignTok = end->next()->astParent();
if (assignTok && assignTok->isAssignmentOp() && assignTok->astOperand1() && assignTok->astOperand1()->variable()) {
if (var && assignTok && assignTok->isAssignmentOp() && assignTok->astOperand1() && assignTok->astOperand1()->variable()) {
const Variable* assignVar = assignTok->astOperand1()->variable();
if (assignVar->isPointer() && !assignVar->isConst() && var->typeScope()) {
const auto& funcMap = var->typeScope()->functionMap;

View File

@ -5900,6 +5900,15 @@ private:
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("struct S {\n" // #10758
" T* h;\n"
" void f(); \n"
"};\n"
"void S::f() {\n"
" char* c = h->x[y];\n"
"};\n");
ASSERT_EQUALS("[test.cpp:5] -> [test.cpp:3]: (style, inconclusive) Technically the member function 'S::f' can be const.\n", errout.str());
}
void const_handleDefaultParameters() {