fix crash in CheckClass::getFileInfo (#3172)
* fix crash in CheckClass::getFileInfo * fix another crash * fix memory leak Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
parent
b1b7fbb63a
commit
1874b9cb0f
|
@ -2859,6 +2859,8 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
|
|||
name = scope->className + "::" + name;
|
||||
scope = scope->nestedIn;
|
||||
}
|
||||
if (name.empty())
|
||||
continue;
|
||||
name.erase(name.size() - 2);
|
||||
if (scope->type != Scope::ScopeType::eGlobal)
|
||||
continue;
|
||||
|
@ -2874,7 +2876,7 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
|
|||
for (const Token *tok = classScope->classDef; tok != classScope->bodyEnd; tok = tok->next())
|
||||
def += tok->str();
|
||||
for (const Function &f: classScope->functionList) {
|
||||
if (f.functionScope->nestedIn != classScope) {
|
||||
if (f.functionScope && f.functionScope->nestedIn != classScope) {
|
||||
for (const Token *tok = f.functionScope->bodyStart; tok != f.functionScope->bodyEnd; tok = tok->next())
|
||||
def += tok->str();
|
||||
}
|
||||
|
|
|
@ -225,6 +225,8 @@ private:
|
|||
TEST_CASE(unsafeClassRefMember);
|
||||
|
||||
TEST_CASE(ctuOneDefinitionRule);
|
||||
|
||||
TEST_CASE(getFileInfo);
|
||||
}
|
||||
|
||||
void checkCopyCtorAndEqOperator(const char code[]) {
|
||||
|
@ -7429,6 +7431,28 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void getFileInfo(const char code[]) {
|
||||
// Clear the error log
|
||||
errout.str("");
|
||||
|
||||
// Tokenize..
|
||||
Tokenizer tokenizer(&settings1, this);
|
||||
std::istringstream istr(code);
|
||||
tokenizer.tokenize(istr, "test.cpp");
|
||||
|
||||
// Check..
|
||||
CheckClass checkClass(&tokenizer, &settings1, this);
|
||||
|
||||
Check::FileInfo * fileInfo = checkClass.getFileInfo(&tokenizer, &settings1);
|
||||
|
||||
delete fileInfo;
|
||||
}
|
||||
|
||||
void getFileInfo() {
|
||||
getFileInfo("void foo() { union { struct { }; }; }"); // don't crash
|
||||
getFileInfo("struct sometype { sometype(); }; sometype::sometype() = delete;"); // don't crash
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestClass)
|
||||
|
|
Loading…
Reference in New Issue