ValueFlow: fix false detection of duplicate values

This commit is contained in:
Daniel Marjamäki 2019-07-24 12:30:33 +02:00
parent cab9f61b79
commit fb7f18ddea
2 changed files with 28 additions and 5 deletions

View File

@ -1702,13 +1702,36 @@ bool Token::addValue(const ValueFlow::Value &value)
// if value already exists, don't add it again
std::list<ValueFlow::Value>::iterator it;
for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) {
// different intvalue => continue
if (it->intvalue != value.intvalue)
continue;
// different types => continue
if (it->valueType != value.valueType)
continue;
// different value => continue
bool differentValue = true;
switch (it->valueType) {
case ValueFlow::Value::ValueType::INT:
case ValueFlow::Value::ValueType::CONTAINER_SIZE:
case ValueFlow::Value::ValueType::BUFFER_SIZE:
differentValue = (it->intvalue != value.intvalue);
break;
case ValueFlow::Value::ValueType::TOK:
case ValueFlow::Value::ValueType::LIFETIME:
differentValue = (it->tokvalue != value.tokvalue);
break;
case ValueFlow::Value::ValueType::FLOAT:
// TODO: Write some better comparison
differentValue = (it->floatValue > value.floatValue || it->floatValue < value.floatValue);
break;
case ValueFlow::Value::ValueType::MOVED:
differentValue = (it->moveKind != value.moveKind);
break;
case ValueFlow::Value::ValueType::UNINIT:
differentValue = false;
break;
}
if (differentValue)
continue;
if ((value.isTokValue() || value.isLifetimeValue()) && (it->tokvalue != value.tokvalue) && (it->tokvalue->str() != value.tokvalue->str()))
continue;

View File

@ -5491,7 +5491,7 @@ static void valueFlowSafeFunctions(TokenList *tokenlist, SymbolDatabase *symbold
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
argValues.back().floatValue = isLow ? low : -1E25f;
argValues.back().errorPath.emplace_back(arg.nameToken(), "Assuming argument has value " + MathLib::toString(argValues.back().floatValue));
argValues.emplace_back(1);
argValues.emplace_back(0);
argValues.back().valueType = ValueFlow::Value::ValueType::FLOAT;
argValues.back().floatValue = isHigh ? high : 1E25f;
argValues.back().errorPath.emplace_back(arg.nameToken(), "Assuming argument has value " + MathLib::toString(argValues.back().floatValue));