diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 25899feb267..cbb8e524023 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -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)) diff --git a/test/teststl.cpp b/test/teststl.cpp index 43f5ca2eda5..2a8c31a7137 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -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& v)\n" + "{\n" + "for (const std::string&s : v)\n" + "}\n"); // don't crash + ASSERT_EQUALS("", errout_str()); } void invalidContainerLoop() {