Fixed #2653 (segmentation fault of cppcheck 'x=b=0;')
This commit is contained in:
parent
7d9872a134
commit
3c2d3ca3a4
|
@ -6095,7 +6095,6 @@ void Tokenizer::simplifyVariableMultipleAssign()
|
|||
if (Token::Match(tok, "%var% = %var% = %num% ;") ||
|
||||
Token::Match(tok, "%var% = %var% = %var% ;"))
|
||||
{
|
||||
|
||||
// skip intermediate assignments
|
||||
Token *tok2 = tok->previous();
|
||||
while (tok2 &&
|
||||
|
@ -6105,7 +6104,7 @@ void Tokenizer::simplifyVariableMultipleAssign()
|
|||
tok2 = tok2->tokAt(-2);
|
||||
}
|
||||
|
||||
if (tok2->str() != ";")
|
||||
if (!tok2 || tok2->str() != ";")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -326,6 +326,9 @@ private:
|
|||
|
||||
// Some simple cleanups of unhandled macros in the global scope
|
||||
TEST_CASE(removeMacrosInGlobalScope);
|
||||
|
||||
// a = b = 0;
|
||||
TEST_CASE(multipleAssignment);
|
||||
}
|
||||
|
||||
|
||||
|
@ -5618,6 +5621,11 @@ private:
|
|||
// remove some unhandled macros in the global scope.
|
||||
ASSERT_EQUALS("void f ( ) { }", tokenizeAndStringify("void f() NOTHROW { }"));
|
||||
}
|
||||
|
||||
void multipleAssignment()
|
||||
{
|
||||
ASSERT_EQUALS("a = b = 0 ;", tokenizeAndStringify("a=b=0;"));
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue