Refactoring: ValueFlow::Value::errorSeverity() will have the logic if value is 'error' or 'warning'
This commit is contained in:
parent
ba2b235e24
commit
f7cda81c0c
|
@ -1787,7 +1787,7 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::V
|
||||||
<< ", otherwise there is negative array index " << index.intvalue << ".";
|
<< ", otherwise there is negative array index " << index.intvalue << ".";
|
||||||
else
|
else
|
||||||
errmsg << "Array index " << index.intvalue << " is out of bounds.";
|
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()
|
CheckBufferOverrun::ArrayInfo::ArrayInfo()
|
||||||
|
|
|
@ -1666,7 +1666,7 @@ void CheckOther::zerodivError(const Token *tok, const ValueFlow::Value *value)
|
||||||
errmsg << "Division by zero.";
|
errmsg << "Division by zero.";
|
||||||
|
|
||||||
reportError(errorPath,
|
reportError(errorPath,
|
||||||
value->condition ? Severity::warning : Severity::error,
|
value->errorSeverity() ? Severity::error : Severity::warning,
|
||||||
value->condition ? "zerodivcond" : "zerodiv",
|
value->condition ? "zerodivcond" : "zerodiv",
|
||||||
errmsg.str(), CWE369, value->inconclusive);
|
errmsg.str(), CWE369, value->inconclusive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ void CheckType::tooBigBitwiseShiftError(const Token *tok, int lhsbits, const Val
|
||||||
if (rhsbits.condition)
|
if (rhsbits.condition)
|
||||||
errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
|
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 + "'.";
|
msg = "Signed integer overflow for expression '" + expr + "'.";
|
||||||
|
|
||||||
reportError(getErrorPath(tok, &value, "Integer overflow"),
|
reportError(getErrorPath(tok, &value, "Integer overflow"),
|
||||||
value.condition ? Severity::warning : Severity::error,
|
value.errorSeverity() ? Severity::error : Severity::warning,
|
||||||
"integerOverflow",
|
"integerOverflow",
|
||||||
msg,
|
msg,
|
||||||
CWE190,
|
CWE190,
|
||||||
|
@ -369,7 +369,7 @@ void CheckType::floatToIntegerOverflowError(const Token *tok, const ValueFlow::V
|
||||||
std::ostringstream errmsg;
|
std::ostringstream errmsg;
|
||||||
errmsg << "Undefined behaviour: float (" << value.floatValue << ") to integer conversion overflow.";
|
errmsg << "Undefined behaviour: float (" << value.floatValue << ") to integer conversion overflow.";
|
||||||
reportError(getErrorPath(tok, &value, "float to integer conversion"),
|
reportError(getErrorPath(tok, &value, "float to integer conversion"),
|
||||||
value.condition ? Severity::warning : Severity::error,
|
value.errorSeverity() ? Severity::error : Severity::warning,
|
||||||
"floatConversionOverflow",
|
"floatConversionOverflow",
|
||||||
errmsg.str(), CWE190, value.inconclusive);
|
errmsg.str(), CWE190, value.inconclusive);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,6 +165,10 @@ namespace ValueFlow {
|
||||||
if (isKnown())
|
if (isKnown())
|
||||||
valueKind = ValueKind::Possible;
|
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).
|
/// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues).
|
||||||
|
|
Loading…
Reference in New Issue