CheckOther::checkTooBigBitwiseShift: improving error messages

This commit is contained in:
Daniel Marjamäki 2014-09-09 17:06:45 +02:00
parent a5b863796c
commit a36b0e55be
2 changed files with 18 additions and 7 deletions

View File

@ -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);
}
//---------------------------------------------------------------------------

View File

@ -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