Fix crash in LoopAnalyzer (#4888)

This commit is contained in:
chrchr-github 2023-03-13 15:44:34 +01:00 committed by GitHub
parent 0b8af4fff7
commit a6c5bb28c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -2781,7 +2781,7 @@ namespace {
if (var->declarationId() == loopVar->varId())
return false;
const Scope* scope = var->scope();
return scope->isNestedIn(bodyTok->scope());
return scope && scope->isNestedIn(bodyTok->scope());
}
private:

View File

@ -5476,6 +5476,23 @@ private:
true);
ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop.\n",
errout.str());
check("class C {\n"
"private:\n"
" QString s;\n"
"public:\n"
" C(QString);\n"
"private slots:\n"
" void f() {\n"
" QVERIFY(QDir(s).exists());\n"
" }\n"
" void f(const QStringList& d) {\n"
" for (QString f : d)\n"
" QDir(s);\n"
" }\n"
"};\n",
true);
ASSERT_EQUALS("", errout.str());
}
void invalidContainer() {