Fixed #2653 (segmentation fault of cppcheck 'x=b=0;')

This commit is contained in:
Daniel Marjamäki 2011-03-26 12:20:23 +01:00
parent 7d9872a134
commit 3c2d3ca3a4
2 changed files with 9 additions and 2 deletions

View File

@ -6095,7 +6095,6 @@ void Tokenizer::simplifyVariableMultipleAssign()
if (Token::Match(tok, "%var% = %var% = %num% ;") || if (Token::Match(tok, "%var% = %var% = %num% ;") ||
Token::Match(tok, "%var% = %var% = %var% ;")) Token::Match(tok, "%var% = %var% = %var% ;"))
{ {
// skip intermediate assignments // skip intermediate assignments
Token *tok2 = tok->previous(); Token *tok2 = tok->previous();
while (tok2 && while (tok2 &&
@ -6105,7 +6104,7 @@ void Tokenizer::simplifyVariableMultipleAssign()
tok2 = tok2->tokAt(-2); tok2 = tok2->tokAt(-2);
} }
if (tok2->str() != ";") if (!tok2 || tok2->str() != ";")
{ {
continue; continue;
} }

View File

@ -326,6 +326,9 @@ private:
// Some simple cleanups of unhandled macros in the global scope // Some simple cleanups of unhandled macros in the global scope
TEST_CASE(removeMacrosInGlobalScope); TEST_CASE(removeMacrosInGlobalScope);
// a = b = 0;
TEST_CASE(multipleAssignment);
} }
@ -5618,6 +5621,11 @@ private:
// remove some unhandled macros in the global scope. // remove some unhandled macros in the global scope.
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }")); ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }"));
} }
void multipleAssignment()
{
ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;"));
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)