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