From afc7fd82ed669730604fe4aee35ae872243e2173 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 18 Mar 2011 20:44:58 -0400 Subject: [PATCH] #2630 (segmentation fault of cppcheck (template ) --- lib/tokenize.cpp | 4 ++-- test/testtokenize.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index a529e3b53..b43e0cd41 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3449,7 +3449,7 @@ void Tokenizer::setVarId() { again = false; - if (tok2->str() == "const") + if (tok2 && tok2->str() == "const") tok2 = tok2->next(); while (Token::Match(tok2, "%var% ::")) @@ -3484,7 +3484,7 @@ void Tokenizer::setVarId() { while (tok2 && (tok2->isName() || tok2->isNumber() || tok2->str() == "*" || tok2->str() == "&" || tok2->str() == ",")) tok2 = tok2->next(); - if (tok2->str() == "(") + if (tok2 && tok2->str() == "(") { tok2 = tok2->link()->next(); if (tok2->str() == "(") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 622cfbc88..54e5b527d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -170,6 +170,7 @@ private: TEST_CASE(varid25); TEST_CASE(varid26); // ticket #1967 (list of function pointers) TEST_CASE(varid27); // Ticket #2280 (same name for namespace and variable) + TEST_CASE(varid28); // ticket #2630 TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall3); @@ -2818,6 +2819,12 @@ private: ASSERT_EQUALS(expected, tokenizeDebugListing(code)); } + void varid28() // ticket #2630 (segmentation fault) + { + tokenizeDebugListing("template \n"); + ASSERT_EQUALS("", errout.str()); + } + void varidFunctionCall1() { const std::string code("void f() {\n"