From 11fa185cae571b0bd18192909183ead0804a8cdd Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 3 Jan 2015 22:36:39 +0100 Subject: [PATCH] Fixed crash on range-based for-loop --- lib/checkstl.cpp | 3 +++ test/teststl.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index e326908aa..e36a581be 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -313,6 +313,9 @@ void CheckStl::stlOutOfBounds() tok = tok->linkAt(1)->tokAt(2); } else tok = tok->next(); + + if (!tok) + continue; tok = tok->next(); // check if the for loop condition is wrong diff --git a/test/teststl.cpp b/test/teststl.cpp index 88d8d3eaa..d9c5cfe2e 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -577,6 +577,11 @@ private: " foo[ii] = 0;\n" "}"); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " for (B b : D()) {}\n" // Don't crash on range-based for-loop + "}"); + ASSERT_EQUALS("", errout.str()); } void STLSizeNoErr() {