@@ -1984,9 +1984,12 @@ static bool isConditionKnown(const Token* tok, bool then)
19841984 if (then)
19851985 op = " &&" ;
19861986 const Token* parent = tok->astParent ();
1987- while (parent && (parent->str () == op || parent->str () == " !" ))
1987+ while (parent && (parent->str () == op || parent->str () == " !" || parent-> isCast () ))
19881988 parent = parent->astParent ();
1989- return Token::Match (parent, " (|;" );
1989+ const Token* top = tok->astTop ();
1990+ if (top && Token::Match (top->previous (), " if|while|for (" ))
1991+ return parent == top || Token::simpleMatch (parent, " ;" );
1992+ return parent && parent->str () != op;
19901993}
19911994
19921995static const std::string& invertAssign (const std::string& assign)
@@ -6353,12 +6356,16 @@ static bool isIntegralOnlyOperator(const Token* tok) {
63536356 return Token::Match (tok, " %|<<|>>|&|^|~|%or%" );
63546357}
63556358
6356- static bool isIntegral (const Token* tok)
6359+ static bool isIntegralOrPointer (const Token* tok)
63576360{
63586361 if (!tok)
63596362 return false ;
63606363 if (astIsIntegral (tok, false ))
63616364 return true ;
6365+ if (astIsPointer (tok))
6366+ return true ;
6367+ if (Token::Match (tok, " NULL|nullptr" ))
6368+ return true ;
63626369 if (tok->valueType ())
63636370 return false ;
63646371 // These operators only work on integers
@@ -6367,7 +6374,7 @@ static bool isIntegral(const Token* tok)
63676374 if (isIntegralOnlyOperator (tok->astParent ()))
63686375 return true ;
63696376 if (Token::Match (tok, " +|-|*|/" ) && tok->isBinaryOp ())
6370- return isIntegral (tok->astOperand1 ()) && isIntegral (tok->astOperand2 ());
6377+ return isIntegralOrPointer (tok->astOperand1 ()) && isIntegralOrPointer (tok->astOperand2 ());
63716378 return false ;
63726379}
63736380
@@ -6400,7 +6407,7 @@ static void valueFlowInferCondition(TokenList* tokenlist,
64006407 setTokenValue (tok, value, settings);
64016408 }
64026409 }
6403- } else if (isIntegral (tok->astOperand1 ()) && isIntegral (tok->astOperand2 ())) {
6410+ } else if (isIntegralOrPointer (tok->astOperand1 ()) && isIntegralOrPointer (tok->astOperand2 ())) {
64046411 std::vector<ValueFlow::Value> result =
64056412 infer (IntegralInferModel{}, tok->str (), tok->astOperand1 ()->values (), tok->astOperand2 ()->values ());
64066413 for (const ValueFlow::Value& value : result) {
0 commit comments