Skip to content

Commit a6c5bb2

Browse files
Fix crash in LoopAnalyzer (#4888)
1 parent 0b8af4f commit a6c5bb2

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,7 @@ namespace {
27812781
if (var->declarationId() == loopVar->varId())
27822782
return false;
27832783
const Scope* scope = var->scope();
2784-
return scope->isNestedIn(bodyTok->scope());
2784+
return scope && scope->isNestedIn(bodyTok->scope());
27852785
}
27862786

27872787
private:

test/teststl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5476,6 +5476,23 @@ class TestStl : public TestFixture {
54765476
true);
54775477
ASSERT_EQUALS("[test.cpp:2]: (style) Consider using std::all_of or std::none_of algorithm instead of a raw loop.\n",
54785478
errout.str());
5479+
5480+
check("class C {\n"
5481+
"private:\n"
5482+
" QString s;\n"
5483+
"public:\n"
5484+
" C(QString);\n"
5485+
"private slots:\n"
5486+
" void f() {\n"
5487+
" QVERIFY(QDir(s).exists());\n"
5488+
" }\n"
5489+
" void f(const QStringList& d) {\n"
5490+
" for (QString f : d)\n"
5491+
" QDir(s);\n"
5492+
" }\n"
5493+
"};\n",
5494+
true);
5495+
ASSERT_EQUALS("", errout.str());
54795496
}
54805497

54815498
void invalidContainer() {

0 commit comments

Comments
 (0)