From a6c5eff1becbf75eb82f2e279622d6acbd326018 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 15 Aug 2011 07:19:49 -0400 Subject: [PATCH] fix #3006 (segmentation fault of cppcheck ( x < () < )) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 24896f843..214d1715c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2420,7 +2420,7 @@ bool Tokenizer::tokenize(std::istream &code, ; else if (level == 0) inclevel = true; - else if (tok2->next()->isStandardType()) + else if (tok2->next() && tok2->next()->isStandardType()) inclevel = true; else if (Token::simpleMatch(tok2, "< typename")) inclevel = true; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 29c77758d..d0ef35440 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -52,6 +52,7 @@ private: TEST_CASE(tokenize16); // #2612 - segfault for "<><<" TEST_CASE(tokenize17); // #2759 TEST_CASE(tokenize18); // tokenize "(X&&Y)" into "( X && Y )" instead of "( X & & Y )" + TEST_CASE(tokenize19); // #3006 (segmentation fault) // don't freak out when the syntax is wrong TEST_CASE(wrong_syntax); @@ -570,6 +571,11 @@ private: ASSERT_EQUALS("( X && Y )", tokenizeAndStringify("(X&&Y)")); } + void tokenize19() // #3006 (segmentation fault) + { + tokenizeAndStringify("x < () <"); + } + void wrong_syntax() { {