@@ -760,7 +760,7 @@ void CheckCondition::multiCondition2()
760760 } else if (!isReturnVar && isSameExpression (true , firstCondition, cond2, *mSettings , true , true , &errorPath)) {
761761 identicalInnerConditionError (firstCondition, cond2, errorPath);
762762 } else if (!isReturnVar && isOverlappingCond (cond2, firstCondition, true )) {
763- identicalInnerConditionError (firstCondition, cond2, errorPath);
763+ overlappingInnerConditionError (firstCondition, cond2, errorPath);
764764 }
765765 }
766766 return ChildrenToVisit::none;
@@ -881,6 +881,21 @@ void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token*
881881 reportError (std::move (errorPath), Severity::warning, " oppositeInnerCondition" , msg, CWE398, Certainty::normal);
882882}
883883
884+ void CheckCondition::overlappingInnerConditionError (const Token *tok1, const Token* tok2, ErrorPath errorPath)
885+ {
886+ if (diag (tok1, tok2))
887+ return ;
888+ const std::string s1 (tok1 ? tok1->expressionString () : " x" );
889+ const std::string s2 (tok2 ? tok2->expressionString () : " x" );
890+ const std::string innerSmt = innerSmtString (tok2);
891+ errorPath.emplace_back (tok1, " outer condition: " + s1);
892+ errorPath.emplace_back (tok2, " overlapping inner condition: " + s2);
893+
894+ const std::string msg (" Overlapping inner '" + innerSmt + " ' condition is always true.\n "
895+ " Overlapping inner '" + innerSmt + " ' condition is always true (outer condition is '" + s1 + " ' and inner condition is '" + s2 + " ')." );
896+ reportError (std::move (errorPath), Severity::warning, " overlappingInnerCondition" , msg, CWE398, Certainty::normal);
897+ }
898+
884899void CheckCondition::identicalInnerConditionError (const Token *tok1, const Token* tok2, ErrorPath errorPath)
885900{
886901 if (diag (tok1, tok2))
@@ -2113,6 +2128,7 @@ void CheckCondition::getErrorMessages(ErrorLogger *errorLogger, const Settings *
21132128 c.comparisonError (nullptr , " &" , 6 , " ==" , 1 , false );
21142129 c.duplicateConditionError (nullptr , nullptr , ErrorPath{});
21152130 c.overlappingElseIfConditionError (nullptr , 1 );
2131+ c.overlappingInnerConditionError (nullptr , nullptr , ErrorPath ());
21162132 c.mismatchingBitAndError (nullptr , 0xf0 , nullptr , 1 );
21172133 c.oppositeInnerConditionError (nullptr , nullptr , ErrorPath{});
21182134 c.identicalInnerConditionError (nullptr , nullptr , ErrorPath{});
0 commit comments