diff --git a/src/checkstl.cpp b/src/checkstl.cpp index 7258b25ca..dc9900080 100644 --- a/src/checkstl.cpp +++ b/src/checkstl.cpp @@ -100,6 +100,9 @@ void CheckStl::stlOutOfBounds() tok = tok->next(); } + if( !tok ) + return; + tok = tok->next(); if (!num || tok->str() != "{") continue; diff --git a/test/teststl.cpp b/test/teststl.cpp index 92184c0d9..30ef71bbf 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -47,6 +47,7 @@ private: TEST_CASE(eraseAssign); TEST_CASE(pushback1); + TEST_CASE(invalidcode); } void check(const char code[]) @@ -247,7 +248,14 @@ private: ASSERT_EQUALS("[test.cpp:5]: (error) After push_back or push_front, the iterator 'it' may be invalid\n", errout.str()); } - + void invalidcode() + { + check("void f()\n" + "{\n" + " for ( \n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestStl)