Skip to content

Commit 2f8e751

Browse files
committed
fixed #14326 - crash (null-pointer-use) in CheckStl::invalidContainer() with incomplete code
1 parent 66078d3 commit 2f8e751

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/checkstl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ void CheckStl::invalidContainer()
11381138
continue;
11391139
if (!astIsContainer(contTok))
11401140
continue;
1141-
for (const Token* tok2 = blockStart; tok2 != blockEnd; tok2 = tok2->next()) {
1141+
for (const Token* tok2 = blockStart; tok2 && tok2 != blockEnd; tok2 = tok2->next()) {
11421142
bool bail = false;
11431143
for (const InvalidContainerAnalyzer::Info::Reference& r : analyzer.invalidatesContainer(tok2)) {
11441144
if (!astIsContainer(r.tok))

test/teststl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6515,6 +6515,13 @@ class TestStl : public TestFixture {
65156515
ASSERT_EQUALS(
65166516
"[test.cpp:7:17] -> [test.cpp:7:24] -> [test.cpp:8:10] -> [test.cpp:9:18]: (error) Reference to vec1 that may be invalid. [invalidContainerReference]\n",
65176517
errout_str());
6518+
6519+
// #14326
6520+
check("void f(const std::vector<std::string>& v)\n"
6521+
"{\n"
6522+
"for (const std::string&s : v)\n"
6523+
"}\n"); // don't crash
6524+
ASSERT_EQUALS("", errout_str());
65186525
}
65196526

65206527
void invalidContainerLoop() {

0 commit comments

Comments
 (0)