From afe95be96688da8699bc91edb074d8b35e436aaf Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 8 Aug 2011 06:58:55 -0400 Subject: [PATCH] fix #2980 (segmentation fault of cppcheck) --- lib/tokenize.cpp | 2 +- test/testtokenize.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e9c758429..b6a64658a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3751,7 +3751,7 @@ void Tokenizer::setVarId() if (level == 1 && Token::Match(tok2, "> %var%")) tok = tok2; - else if (level > 1 && tok2->str() == ">") + else if (level > 1 && tok2 && tok2->str() == ">") { level--; if (level == 0) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 814be3aca..a954e43de 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -181,6 +181,7 @@ private: TEST_CASE(varid33); // ticket #2875 (segmentation fault) TEST_CASE(varid34); // ticket #2825 TEST_CASE(varid35); // ticket #2937 + TEST_CASE(varid36); // ticket #2980 (segmentation fault) TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -3016,6 +3017,13 @@ private: TODO_ASSERT_EQUALS(expected, actual, tokenizeDebugListing(code)); } + void varid36() // ticket #2980 (segmentation fault) + { + const std::string code("#elif A\n" + "A,a