From ce9f6bdb56e421786572997997ca3e5bdc108434 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Mon, 10 Sep 2012 17:33:52 +0200 Subject: [PATCH] Fixed segfault #4182 --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c3f3ada1b..364168585 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2528,7 +2528,7 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::mapstr()) != variableId.end() && tok2->previous()->str() != "::") { ++typeCount; tok2 = tok2->next(); - if (tok2->str() != "::") + if (!tok2 || tok2->str() != "::") break; } else { ++typeCount; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 1951cf0df..4f93a0cba 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -63,6 +63,7 @@ private: TEST_CASE(wrong_syntax3); // #3544 TEST_CASE(wrong_syntax4); // #3618 TEST_CASE(wrong_syntax_if_macro); // #2518 - if MACRO() + TEST_CASE(garbageCode); TEST_CASE(foreach); // #3690 @@ -702,6 +703,10 @@ private: ASSERT_EQUALS("", errout.str()); } + void garbageCode() { + tokenizeAndStringify("struct x foo_t; foo_t typedef y;"); + } + void foreach() { // #3690 const std::string code("void f() { for each ( char c in MyString ) { Console::Write(c); } }");