Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ void CheckStl::invalidContainer()
continue;
if (!astIsContainer(contTok))
continue;
for (const Token* tok2 = blockStart; tok2 != blockEnd; tok2 = tok2->next()) {
for (const Token* tok2 = blockStart; tok2 && tok2 != blockEnd; tok2 = tok2->next()) {
bool bail = false;
for (const InvalidContainerAnalyzer::Info::Reference& r : analyzer.invalidatesContainer(tok2)) {
if (!astIsContainer(r.tok))
Expand Down
7 changes: 7 additions & 0 deletions test/teststl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6515,6 +6515,13 @@ class TestStl : public TestFixture {
ASSERT_EQUALS(
"[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",
errout_str());

// #14326
check("void f(const std::vector<std::string>& v)\n"
"{\n"
"for (const std::string&s : v)\n"
"}\n"); // don't crash
ASSERT_EQUALS("", errout_str());
}

void invalidContainerLoop() {
Expand Down
Loading