@@ -2052,64 +2052,68 @@ static bool isAdjacent(const ValueFlow::Value& x, const ValueFlow::Value& y)
20522052 return std::abs (x.intvalue - y.intvalue ) == 1 ;
20532053}
20542054
2055- static bool removePointValue (std::list<ValueFlow::Value>& values, ValueFlow::Value& x)
2055+ static bool removePointValue (std::list<ValueFlow::Value>& values, std::list< ValueFlow::Value>::iterator & x)
20562056{
2057- const bool isPoint = x. bound == ValueFlow::Value::Bound::Point;
2057+ const bool isPoint = x-> bound == ValueFlow::Value::Bound::Point;
20582058 if (!isPoint)
2059- x. decreaseRange ();
2059+ x-> decreaseRange ();
20602060 else
2061- values.remove (x);
2061+ x = values.erase (x);
20622062 return isPoint;
20632063}
20642064
20652065static bool removeContradiction (std::list<ValueFlow::Value>& values)
20662066{
20672067 bool result = false ;
2068- for (ValueFlow::Value& x : values) {
2069- if (x. isNonValue ())
2068+ for (auto itx = values. begin (); itx != values. end (); ++itx ) {
2069+ if (itx-> isNonValue ())
20702070 continue ;
2071- for (ValueFlow::Value& y : values) {
2072- if (y.isNonValue ())
2071+
2072+ auto ity = itx;
2073+ ++ity;
2074+ for (; ity != values.end (); ++ity) {
2075+ if (ity->isNonValue ())
20732076 continue ;
2074- if (x == y )
2077+ if (*itx == *ity )
20752078 continue ;
2076- if (x. valueType != y. valueType )
2079+ if (itx-> valueType != ity-> valueType )
20772080 continue ;
2078- if (x. isImpossible () == y. isImpossible ())
2081+ if (itx-> isImpossible () == ity-> isImpossible ())
20792082 continue ;
2080- if (x. isSymbolicValue () && !ValueFlow::Value::sameToken (x. tokvalue , y. tokvalue ))
2083+ if (itx-> isSymbolicValue () && !ValueFlow::Value::sameToken (itx-> tokvalue , ity-> tokvalue ))
20812084 continue ;
2082- if (!x. equalValue (y )) {
2083- auto compare = [](const ValueFlow::Value& x, const ValueFlow::Value& y) {
2084- return x. compareValue (y, less{});
2085+ if (!itx-> equalValue (*ity )) {
2086+ auto compare = [](const std::list< ValueFlow::Value>::const_iterator & x, const std::list< ValueFlow::Value>::const_iterator & y) {
2087+ return x-> compareValue (* y, less{});
20852088 };
2086- const ValueFlow::Value& maxValue = std::max (x, y , compare);
2087- const ValueFlow::Value& minValue = std::min (x, y , compare);
2089+ auto itMax = std::max (itx, ity , compare);
2090+ auto itMin = std::min (itx, ity , compare);
20882091 // TODO: Adjust non-points instead of removing them
2089- if (maxValue. isImpossible () && maxValue. bound == ValueFlow::Value::Bound::Upper) {
2090- values.remove (minValue );
2092+ if (itMax-> isImpossible () && itMax-> bound == ValueFlow::Value::Bound::Upper) {
2093+ values.erase (itMin );
20912094 return true ;
20922095 }
2093- if (minValue. isImpossible () && minValue. bound == ValueFlow::Value::Bound::Lower) {
2094- values.remove (maxValue );
2096+ if (itMin-> isImpossible () && itMin-> bound == ValueFlow::Value::Bound::Lower) {
2097+ values.erase (itMax );
20952098 return true ;
20962099 }
20972100 continue ;
20982101 }
2099- const bool removex = !x. isImpossible () || y. isKnown ();
2100- const bool removey = !y. isImpossible () || x. isKnown ();
2101- if (x. bound == y. bound ) {
2102+ const bool removex = !itx-> isImpossible () || ity-> isKnown ();
2103+ const bool removey = !ity-> isImpossible () || itx-> isKnown ();
2104+ if (itx-> bound == ity-> bound ) {
21022105 if (removex)
2103- values.remove (x );
2106+ values.erase (itx );
21042107 if (removey)
2105- values.remove (y);
2108+ values.erase (ity);
2109+ // itx and ity are invalidated
21062110 return true ;
21072111 }
21082112 result = removex || removey;
21092113 bool bail = false ;
2110- if (removex && removePointValue (values, x ))
2114+ if (removex && removePointValue (values, itx ))
21112115 bail = true ;
2112- if (removey && removePointValue (values, y ))
2116+ if (removey && removePointValue (values, ity ))
21132117 bail = true ;
21142118 if (bail)
21152119 return true ;
0 commit comments