fix #2980 (segmentation fault of cppcheck)

This commit is contained in:
Robert Reif 2011-08-08 06:58:55 -04:00
parent 403b508371
commit afe95be966
2 changed files with 9 additions and 1 deletions

View File

@ -3751,7 +3751,7 @@ void Tokenizer::setVarId()
if (level == 1 && Token::Match(tok2, "> %var%")) if (level == 1 && Token::Match(tok2, "> %var%"))
tok = tok2; tok = tok2;
else if (level > 1 && tok2->str() == ">") else if (level > 1 && tok2 && tok2->str() == ">")
{ {
level--; level--;
if (level == 0) if (level == 0)

View File

@ -181,6 +181,7 @@ private:
TEST_CASE(varid33); // ticket #2875 (segmentation fault) TEST_CASE(varid33); // ticket #2875 (segmentation fault)
TEST_CASE(varid34); // ticket #2825 TEST_CASE(varid34); // ticket #2825
TEST_CASE(varid35); // ticket #2937 TEST_CASE(varid35); // ticket #2937
TEST_CASE(varid36); // ticket #2980 (segmentation fault)
TEST_CASE(varidFunctionCall1); TEST_CASE(varidFunctionCall1);
TEST_CASE(varidFunctionCall2); TEST_CASE(varidFunctionCall2);
TEST_CASE(varidFunctionCall3); TEST_CASE(varidFunctionCall3);
@ -3016,6 +3017,13 @@ private:
TODO_ASSERT_EQUALS(expected, actual, tokenizeDebugListing(code)); TODO_ASSERT_EQUALS(expected, actual, tokenizeDebugListing(code));
} }
void varid36() // ticket #2980 (segmentation fault)
{
const std::string code("#elif A\n"
"A,a<b<x0;\n");
ASSERT_EQUALS("", errout.str());
}
void varidFunctionCall1() void varidFunctionCall1()
{ {
const std::string code("void f() {\n" const std::string code("void f() {\n"