avoid some unnecessary code execution (#4962)
This commit is contained in:
parent
6eae4e71f6
commit
1cd1cbabe9
|
@ -137,12 +137,6 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
|
|||
return;
|
||||
}
|
||||
|
||||
const ErrorPath errorPath = getErrorPath(tok, &rhsbits, "Shift");
|
||||
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "Shifting signed " << lhsbits << "-bit value by " << rhsbits.intvalue << " bits is " + behaviour + " behaviour";
|
||||
if (rhsbits.condition)
|
||||
errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
|
||||
|
||||
Severity::SeverityType severity = rhsbits.errorSeverity() ? Severity::error : Severity::warning;
|
||||
if (cpp14)
|
||||
|
@ -150,6 +144,13 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
|
|||
|
||||
if ((severity == Severity::portability) && !mSettings->severity.isEnabled(Severity::portability))
|
||||
return;
|
||||
const ErrorPath errorPath = getErrorPath(tok, &rhsbits, "Shift");
|
||||
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "Shifting signed " << lhsbits << "-bit value by " << rhsbits.intvalue << " bits is " + behaviour + " behaviour";
|
||||
if (rhsbits.condition)
|
||||
errmsg << ". See condition at line " << rhsbits.condition->linenr() << ".";
|
||||
|
||||
reportError(errorPath, severity, id, errmsg.str(), CWE758, rhsbits.isInconclusive() ? Certainty::inconclusive : Certainty::normal);
|
||||
}
|
||||
|
||||
|
|
|
@ -116,6 +116,10 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
|
|||
// Format callstack
|
||||
for (const ErrorPathItem& e: errorPath) {
|
||||
const Token *tok = e.first;
|
||||
// --errorlist can provide null values here
|
||||
if (!tok)
|
||||
continue;
|
||||
|
||||
std::string info = e.second;
|
||||
|
||||
if (info.compare(0,8,"$symbol:") == 0 && info.find('\n') < info.size()) {
|
||||
|
@ -124,9 +128,7 @@ ErrorMessage::ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenLis
|
|||
info = replaceStr(info.substr(pos+1), "$symbol", symbolName);
|
||||
}
|
||||
|
||||
// --errorlist can provide null values here
|
||||
if (tok)
|
||||
callStack.emplace_back(tok, info, tokenList);
|
||||
callStack.emplace_back(tok, info, tokenList);
|
||||
}
|
||||
|
||||
if (tokenList && !tokenList->getFiles().empty())
|
||||
|
|
|
@ -3463,15 +3463,14 @@ const std::string& Type::name() const
|
|||
|
||||
void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, const std::string &msg) const
|
||||
{
|
||||
if (tok && mSettings.debugwarnings) {
|
||||
if (tok && mSettings.debugwarnings && mErrorLogger) {
|
||||
const std::list<const Token*> locationList(1, tok);
|
||||
const ErrorMessage errmsg(locationList, &mTokenizer.list,
|
||||
Severity::debug,
|
||||
type,
|
||||
msg,
|
||||
Certainty::normal);
|
||||
if (mErrorLogger)
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1144,15 +1144,14 @@ void TemplateSimplifier::useDefaultArgumentValues(TokenAndName &declaration)
|
|||
while (it != eq.cend()) {
|
||||
// check for end
|
||||
if (!it->end) {
|
||||
if (mSettings.debugwarnings) {
|
||||
if (mSettings.debugwarnings && mErrorLogger && mSettings.severity.isEnabled(Severity::debug)) {
|
||||
const std::list<const Token*> locationList(1, it->eq);
|
||||
const ErrorMessage errmsg(locationList, &mTokenizer.list,
|
||||
Severity::debug,
|
||||
"noparamend",
|
||||
"TemplateSimplifier couldn't find end of template parameter.",
|
||||
Certainty::normal);
|
||||
if (mErrorLogger && mSettings.severity.isEnabled(Severity::debug))
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3045,20 +3044,21 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
|
|||
numberOfTemplateInstantiations = mTemplateInstantiations.size();
|
||||
++recursiveCount;
|
||||
if (recursiveCount > mSettings.maxTemplateRecursion) {
|
||||
std::list<std::string> typeStringsUsedInTemplateInstantiation;
|
||||
const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">";
|
||||
if (mErrorLogger && mSettings.severity.isEnabled(Severity::information)) {
|
||||
std::list<std::string> typeStringsUsedInTemplateInstantiation;
|
||||
const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">";
|
||||
|
||||
const std::list<const Token *> callstack(1, instantiation.token());
|
||||
const ErrorMessage errmsg(callstack,
|
||||
&mTokenizer.list,
|
||||
Severity::information,
|
||||
"templateRecursion",
|
||||
"TemplateSimplifier: max template recursion ("
|
||||
+ MathLib::toString(mSettings.maxTemplateRecursion)
|
||||
+ ") reached for template '"+typeForNewName+"'. You might want to limit Cppcheck recursion.",
|
||||
Certainty::normal);
|
||||
if (mErrorLogger && mSettings.severity.isEnabled(Severity::information))
|
||||
const std::list<const Token *> callstack(1, instantiation.token());
|
||||
const ErrorMessage errmsg(callstack,
|
||||
&mTokenizer.list,
|
||||
Severity::information,
|
||||
"templateRecursion",
|
||||
"TemplateSimplifier: max template recursion ("
|
||||
+ MathLib::toString(mSettings.maxTemplateRecursion)
|
||||
+ ") reached for template '"+typeForNewName+"'. You might want to limit Cppcheck recursion.",
|
||||
Certainty::normal);
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
}
|
||||
|
||||
// bail out..
|
||||
break;
|
||||
|
@ -3896,15 +3896,14 @@ void TemplateSimplifier::simplifyTemplates(
|
|||
}
|
||||
|
||||
if (passCount == passCountMax) {
|
||||
if (mSettings.debugwarnings) {
|
||||
if (mSettings.debugwarnings && mErrorLogger) {
|
||||
const std::list<const Token*> locationList(1, mTokenList.front());
|
||||
const ErrorMessage errmsg(locationList, &mTokenizer.list,
|
||||
Severity::debug,
|
||||
"debug",
|
||||
"TemplateSimplifier: pass count limit hit before simplifications were finished.",
|
||||
Certainty::normal);
|
||||
if (mErrorLogger)
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
mErrorLogger->reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue