#6895 segmentation fault (invalid code) in CheckCondition::isOppositeCond

This commit is contained in:
amai2012 2015-07-30 17:19:19 +02:00
parent bd56381fd2
commit 249a05126b
2 changed files with 7 additions and 2 deletions

View File

@ -383,9 +383,9 @@ bool CheckCondition::isOppositeCond(bool isNot, const Token * const cond1, const
if (cond1->str() == "!") {
if (cond2->str() == "!=") {
if (cond2->astOperand1()->str() == "0")
if (cond2->astOperand1() && cond2->astOperand1()->str() == "0")
return isSameExpression(_tokenizer, cond1->astOperand1(), cond2->astOperand2(), constFunctions);
if (cond2->astOperand2()->str() == "0")
if (cond2->astOperand2() && cond2->astOperand2()->str() == "0")
return isSameExpression(_tokenizer, cond1->astOperand1(), cond2->astOperand1(), constFunctions);
}
return isSameExpression(_tokenizer, cond1->astOperand1(), cond2, constFunctions);

View File

@ -147,6 +147,7 @@ private:
TEST_CASE(garbageCode105); // #6859
TEST_CASE(garbageCode106);
TEST_CASE(garbageCode107);
TEST_CASE(garbageCode108);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -829,6 +830,10 @@ private:
ASSERT_THROW(checkCode("enum { val = 1{ }; { const} }; { } Bar { const int A = val const } ;"), InternalError);
}
void garbageCode108() { // #6895 "segmentation fault (invalid code) in CheckCondition::isOppositeCond"
checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }");
}
void garbageValueFlow() {
// #6089