Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,20 @@ 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)
severity = Severity::portability;

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

Expand Down
8 changes: 5 additions & 3 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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())
Expand Down
5 changes: 2 additions & 3 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3460,15 +3460,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);
}
}

Expand Down
37 changes: 18 additions & 19 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -3029,20 +3028,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) + ">";

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))
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);
mErrorLogger->reportErr(errmsg);
}

// bail out..
break;
Expand Down Expand Up @@ -3880,15 +3880,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);
}
}

Expand Down