Fix crash on nullptr (#4582)

* Update tokenlist.cpp

* Update testincompletestatement.cpp

* Fix #11370 FP constStatement with lambda

* Format

* Fix crash on nullptr

* Emit syntax error

* Fix test

* Use strAt()

* Fix another crash on nullptr

* Update testconstructors.cpp

* Fix crash on nullptr

* Fix test
This commit is contained in:
chrchr-github 2022-11-13 23:04:51 +01:00 committed by GitHub
parent 701d381895
commit e3939d32d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -697,7 +697,7 @@ void CheckClass::assignAllVarsVisibleFromScope(std::vector<Usage>& usageList, co
for (const Type::BaseInfo& i : scope->definedType->derivedFrom) {
const Type *derivedFrom = i.type;
if (derivedFrom)
if (derivedFrom && derivedFrom->classScope)
assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope);
}
}

View File

@ -1440,7 +1440,7 @@ private:
"[test.cpp:9]: (warning) Member variable 'B::ca' is not assigned a value in 'B::operator='.\n",
errout.str());
check("class C : B {\n"
check("class C : B {\n" // don't crash
" virtual C& operator=(C& c);\n"
"};\n"
"class D : public C {\n"
@ -1448,6 +1448,16 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
check("struct B;\n" // don't crash
"struct D : B { D& operator=(const D&); };\n"
"struct E : D { E& operator=(const E& rhs); };\n"
"E& E::operator=(const E& rhs) {\n"
" if (this != &rhs)\n"
" D::operator=(rhs);\n"
" return *this;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void initvar_derived_pod_struct_with_union() {