Refactoring: ValueFlow::Value::errorSeverity() will have the logic if value is 'error' or 'warning'

This commit is contained in:
Daniel Marjamäki 2017-05-23 11:43:56 +02:00
parent ba2b235e24
commit f7cda81c0c
4 changed files with 9 additions and 5 deletions

View File

@ -1787,7 +1787,7 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::V
<< ", otherwise there is negative array index " << index.intvalue << ".";
else
errmsg << "Array index " << index.intvalue << " is out of bounds.";
reportError(errorPath, index.condition ? Severity::warning : Severity::error, "negativeIndex", errmsg.str(), CWE786, index.inconclusive);
reportError(errorPath, index.errorSeverity() ? Severity::error : Severity::warning, "negativeIndex", errmsg.str(), CWE786, index.inconclusive);
}
CheckBufferOverrun::ArrayInfo::ArrayInfo()

View File

@ -1666,7 +1666,7 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
errmsg << "Division by zero.";
reportError(errorPath,
value->condition ? Severity::warning : Severity::error,
value->errorSeverity() ? Severity::error : Severity::warning,
value->condition ? "zerodivcond" : "zerodiv",
errmsg.str(), CWE369, value->inconclusive);
}

View File

@ -99,7 +99,7 @@ void CheckType::tooBigBitwiseShiftError(const Token *tok, int lhsbits, const Val
if (rhsbits.condition)
errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
reportError(errorPath, rhsbits.condition ? Severity::warning : Severity::error, "shiftTooManyBits", errmsg.str(), CWE758, rhsbits.inconclusive);
reportError(errorPath, rhsbits.errorSeverity() ? Severity::error : Severity::warning, "shiftTooManyBits", errmsg.str(), CWE758, rhsbits.inconclusive);
}
//---------------------------------------------------------------------------
@ -156,7 +156,7 @@ void CheckType::integerOverflowError(const Token *tok, const ValueFlow::Value &v
msg = "Signed integer overflow for expression '" + expr + "'.";
reportError(getErrorPath(tok, &value, "Integer overflow"),
value.condition ? Severity::warning : Severity::error,
value.errorSeverity() ? Severity::error : Severity::warning,
"integerOverflow",
msg,
CWE190,
@ -369,7 +369,7 @@ void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::V
std::ostringstream errmsg;
errmsg << "Undefined behaviour: float (" << value.floatValue << ") to integer conversion overflow.";
reportError(getErrorPath(tok, &value, "float to integer conversion"),
value.condition ? Severity::warning : Severity::error,
value.errorSeverity() ? Severity::error : Severity::warning,
"floatConversionOverflow",
errmsg.str(), CWE190, value.inconclusive);
}

View File

@ -165,6 +165,10 @@ namespace ValueFlow {
if (isKnown())
valueKind = ValueKind::Possible;
}
bool errorSeverity() const {
return !condition && !defaultArg;
}
};
/// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues).