CheckOther::checkTooBigBitwiseShift: improving error messages
This commit is contained in:
parent
a5b863796c
commit
a36b0e55be
|
@ -2702,17 +2702,28 @@ void CheckOther::checkTooBigBitwiseShift()
|
|||
|
||||
// Get biggest rhs value. preferably a value which doesn't have 'condition'.
|
||||
const ValueFlow::Value *value = tok->astOperand2()->getValueGE(lhsbits, _settings);
|
||||
if (value)
|
||||
tooBigBitwiseShiftError(tok, lhsbits, value->intvalue);
|
||||
if (!value)
|
||||
continue;
|
||||
if (value->condition && !_settings->isEnabled("warning"))
|
||||
continue;
|
||||
if (value->inconclusive && !_settings->inconclusive)
|
||||
continue;
|
||||
tooBigBitwiseShiftError(tok, lhsbits, *value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOther::tooBigBitwiseShiftError(const Token *tok, int lhsbits, MathLib::bigint rhsbits)
|
||||
void CheckOther::tooBigBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits)
|
||||
{
|
||||
std::list<const Token*> callstack;
|
||||
callstack.push_back(tok);
|
||||
if (rhsbits.condition)
|
||||
callstack.push_back(rhsbits.condition);
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "Shifting " << lhsbits << "-bit value by " << rhsbits << " bits is undefined behaviour";
|
||||
reportError(tok, Severity::error, "shiftTooManyBits", errmsg.str());
|
||||
errmsg << "Shifting " << lhsbits << "-bit value by " << rhsbits.intvalue << " bits is undefined behaviour";
|
||||
if (rhsbits.condition)
|
||||
errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
|
||||
reportError(callstack, rhsbits.condition ? Severity::warning : Severity::error, "shiftTooManyBits", errmsg.str(), rhsbits.inconclusive);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -290,7 +290,7 @@ private:
|
|||
void SuspiciousSemicolonError(const Token *tok);
|
||||
void doubleCloseDirError(const Token *tok, const std::string &varname);
|
||||
void negativeBitwiseShiftError(const Token *tok);
|
||||
void tooBigBitwiseShiftError(const Token *tok, int lhsbits, MathLib::bigint rhsbits);
|
||||
void tooBigBitwiseShiftError(const Token *tok, int lhsbits, const ValueFlow::Value &rhsbits);
|
||||
void redundantCopyError(const Token *tok, const std::string &varname);
|
||||
void incompleteArrayFillError(const Token* tok, const std::string& buffer, const std::string& function, bool boolean);
|
||||
void varFuncNullUBError(const Token *tok);
|
||||
|
@ -309,7 +309,7 @@ private:
|
|||
c.doubleFreeError(0, "varname");
|
||||
c.invalidPointerCastError(0, "float", "double", false);
|
||||
c.negativeBitwiseShiftError(0);
|
||||
c.tooBigBitwiseShiftError(0, 32, 64);
|
||||
c.tooBigBitwiseShiftError(0, 32, ValueFlow::Value(64));
|
||||
c.checkPipeParameterSizeError(0, "varname", "dimension");
|
||||
|
||||
//performance
|
||||
|
|
Loading…
Reference in New Issue