diff --git a/lib/checkcondition.cpp b/lib/checkcondition.cpp index d58d877ca..396cbf3a0 100644 --- a/lib/checkcondition.cpp +++ b/lib/checkcondition.cpp @@ -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); diff --git a/test/testgarbage.cpp b/test/testgarbage.cpp index 7e39655eb..54dd129a7 100644 --- a/test/testgarbage.cpp +++ b/test/testgarbage.cpp @@ -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