diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 595513a26..6874174f5 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -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() diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 10efc0d18..c872a7e41 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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); } diff --git a/lib/checktype.cpp b/lib/checktype.cpp index a5e449663..4660b4a35 100644 --- a/lib/checktype.cpp +++ b/lib/checktype.cpp @@ -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); } diff --git a/lib/valueflow.h b/lib/valueflow.h index 0293460b8..aaaecd297 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -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).