Fix segmentation fault that happens with invalid code.

This commit is contained in:
Reijo Tomperi 2009-03-05 23:22:00 +02:00
parent 42a9eb9e53
commit 6fcb89f136
2 changed files with 12 additions and 1 deletions

View File

@ -100,6 +100,9 @@ void CheckStl::stlOutOfBounds()
tok = tok->next(); tok = tok->next();
} }
if( !tok )
return;
tok = tok->next(); tok = tok->next();
if (!num || tok->str() != "{") if (!num || tok->str() != "{")
continue; continue;

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(eraseAssign); TEST_CASE(eraseAssign);
TEST_CASE(pushback1); TEST_CASE(pushback1);
TEST_CASE(invalidcode);
} }
void check(const char code[]) 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()); 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) REGISTER_TEST(TestStl)