Skip to content

Commit

Permalink
use inline suppressions
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Nov 27, 2023
1 parent 6ac1141 commit e8e6529
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 16 deletions.
14 changes: 0 additions & 14 deletions .selfcheck_suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ varid0:gui/projectfile.cpp
naming-privateMemberVariable:gui/test/cppchecklibrarydata/testcppchecklibrarydata.h
symbolDatabaseWarning:*/moc_*.cpp
simplifyUsing:*/moc_*.cpp
bitwiseOnBoolean:lib/library.cpp
templateInstantiation:lib/checkunusedfunctions.cpp
templateInstantiation:lib/errorlogger.cpp
templateInstantiation:lib/liobrary.cpp
shadowFunction:lib/checkbufferoverrun.cpp
shadowFunction:lib/checkclass.cpp
shadowFunction:lib/checknullpointer.cpp
shadowFunction:lib/cppcheck.cpp
shadowFunction:lib/fwdanalysis.cpp
shadowFunction:lib/library.cpp
shadowFunction:lib/symboldatabase.cpp
shadowFunction:lib/templatesimplifier.cpp
shadowFunction:lib/token.cpp
shadowFunction:tools/triage/mainwindow.cpp

# warnings in Qt generated code we cannot fix
funcArgNamesDifferent:*/moc_*.cpp
Expand Down
1 change: 1 addition & 0 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con

Check::FileInfo * CheckBufferOverrun::loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
{
// cppcheck-suppress shadowFunction - TODO: fix this
const std::string arrayIndex("array-index");
const std::string pointerArith("pointer-arith");

Expand Down
1 change: 1 addition & 0 deletions lib/checkclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
return false;
const Token* assignTok = end->next()->astParent();
if (var && assignTok && assignTok->isAssignmentOp() && assignTok->astOperand1() && assignTok->astOperand1()->variable()) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Variable* assignVar = assignTok->astOperand1()->variable();
if (assignVar->isPointer() && !assignVar->isConst() && var->typeScope()) {
const auto& funcMap = var->typeScope()->functionMap;
Expand Down
2 changes: 2 additions & 0 deletions lib/checknullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static std::string arithmeticTypeString(const Token *tok)

void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow::Value *value, bool inconclusive)
{
// cppcheck-suppress shadowFunction - TODO: fix this
std::string arithmetic = arithmeticTypeString(tok);
std::string errmsg;
if (tok && tok->str()[0] == '-') {
Expand All @@ -532,6 +533,7 @@ void CheckNullPointer::pointerArithmeticError(const Token* tok, const ValueFlow:

void CheckNullPointer::redundantConditionWarning(const Token* tok, const ValueFlow::Value *value, const Token *condition, bool inconclusive)
{
// cppcheck-suppress shadowFunction - TODO: fix this
std::string arithmetic = arithmeticTypeString(tok);
std::string errmsg;
if (tok && tok->str()[0] == '-') {
Expand Down
4 changes: 3 additions & 1 deletion lib/checkunusedfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,10 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo
}
if (std::strcmp(e2->Name(),"functiondecl") == 0) {
const char* lineNumber = e2->Attribute("lineNumber");
if (lineNumber)
if (lineNumber) {
// cppcheck-suppress templateInstantiation - TODO: fix this - see #11631
decls[functionName] = Location(sourcefile, strToInt<int>(lineNumber));
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
const std::time_t maxTime = mSettings.checksMaxTime > 0 ? std::time(nullptr) + mSettings.checksMaxTime : 0;

// call all "runChecks" in all registered Check classes
// cppcheck-suppress shadowFunction - TODO: fix this
for (Check *check : Check::instances()) {
if (Settings::terminated())
return;
Expand Down Expand Up @@ -1104,6 +1105,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
mAnalyzerInformation.setFileInfo("ctu", fi1->toString());
}

// cppcheck-suppress shadowFunction - TODO: fix this
for (const Check *check : Check::instances()) {
if (doUnusedFunctionOnly && dynamic_cast<const CheckUnusedFunctions*>(check) == nullptr)
continue;
Expand Down Expand Up @@ -1735,6 +1737,7 @@ bool CppCheck::analyseWholeProgram()
ctu.nestedCalls.insert(ctu.nestedCalls.end(), fi2->nestedCalls.cbegin(), fi2->nestedCalls.cend());
}
}
// cppcheck-suppress shadowFunction - TODO: fix this
for (Check *check : Check::instances())
errors |= check->analyseWholeProgram(&ctu, mFileInfo, mSettings, *this); // TODO: ctu
return errors && (mExitCode > 0);
Expand Down Expand Up @@ -1785,6 +1788,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
ctuFileInfo.loadFromXml(e);
continue;
}
// cppcheck-suppress shadowFunction - TODO: fix this
for (const Check *check : Check::instances()) {
if (checkClassAttr == check->name())
fileInfoList.push_back(check->loadFileInfoFromXml(e));
Expand All @@ -1796,6 +1800,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
CTU::maxCtuDepth = mSettings.maxCtuDepth;

// Analyse the tokens
// cppcheck-suppress shadowFunction - TODO: fix this
for (Check *check : Check::instances())
check->analyseWholeProgram(&ctuFileInfo, fileInfoList, mSettings, *this);

Expand Down
1 change: 1 addition & 0 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
severity = attr ? severityFromString(attr) : Severity::none;

attr = errmsg->Attribute("cwe");
// cppcheck-suppress templateInstantiation - TODO: fix this - see #11631
cwe.id = attr ? strToInt<unsigned short>(attr) : 0;

attr = errmsg->Attribute("inconclusive");
Expand Down
1 change: 1 addition & 0 deletions lib/fwdanalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
// ({ .. })
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
return Result(Result::Type::BAILOUT);
// cppcheck-suppress shadowFunction - TODO: fix this
const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
if (reassign)
return Result(Result::Type::WRITE, parent->astParent());
Expand Down
7 changes: 6 additions & 1 deletion lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
if (end)
mExecutableBlocks[extension].setEnd(end);
const char * offset = blocknode->Attribute("offset");
if (offset)
if (offset) {
// cppcheck-suppress templateInstantiation - TODO: fix this - see #11631
mExecutableBlocks[extension].setOffset(strToInt<int>(offset));
}
}

else
Expand Down Expand Up @@ -706,6 +708,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
mReturnValueType[name] = type;
if (const char *container = functionnode->Attribute("container"))
mReturnValueContainer[name] = strToInt<int>(container);
// cppcheck-suppress shadowFunction - TODO: fix this
if (const char *unknownReturnValues = functionnode->Attribute("unknownValues")) {
if (std::strcmp(unknownReturnValues, "all") == 0) {
std::vector<MathLib::bigint> values{LLONG_MIN, LLONG_MAX};
Expand Down Expand Up @@ -1305,6 +1308,7 @@ bool Library::isCompliantValidationExpression(const char* p)
error |= (*(p + 1) == '-');
}
else if (*p == ':') {
// cppcheck-suppress bitwiseOnBoolean - TODO: fix this
error |= range | (*(p + 1) == '.');
range = true;
has_dot = false;
Expand All @@ -1319,6 +1323,7 @@ bool Library::isCompliantValidationExpression(const char* p)
has_dot = false;
has_E = false;
} else if (*p == '.') {
// cppcheck-suppress bitwiseOnBoolean - TODO: fix this
error |= has_dot | (!std::isdigit(*(p + 1)));
has_dot = true;
} else if (*p == 'E' || *p == 'e') {
Expand Down
1 change: 1 addition & 0 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,7 @@ const Type* Variable::smartPointerType() const
while (Token::Match(typeTok, "%name%|::"))
typeTok = typeTok->next();
if (Token::Match(typeTok, "< %name% >")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope* scope = typeTok->scope();
const Type* ptrType{};
while (scope && !ptrType) {
Expand Down
1 change: 1 addition & 0 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2946,6 +2946,7 @@ bool TemplateSimplifier::matchSpecialization(
startToken = startToken->previous();
if (!Token::simpleMatch(startToken, "template <"))
continue;
// cppcheck-suppress shadowFunction - TODO: fix this
std::vector<const Token *> templateParameters;
getTemplateParametersInDeclaration(startToken->tokAt(2), templateParameters);

Expand Down
16 changes: 16 additions & 0 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ void Token::swapWithNext()
std::swap(mFlags, mNext->mFlags);
std::swap(mImpl, mNext->mImpl);
if (mImpl->mTemplateSimplifierPointers)
// cppcheck-suppress shadowFunction - TODO: fix this
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
templateSimplifierPointer->token(this);
}

if (mNext->mImpl->mTemplateSimplifierPointers)
// cppcheck-suppress shadowFunction - TODO: fix this
for (auto *templateSimplifierPointer : *mNext->mImpl->mTemplateSimplifierPointers) {
templateSimplifierPointer->token(mNext);
}
Expand All @@ -341,6 +343,7 @@ void Token::takeData(Token *fromToken)
mImpl = fromToken->mImpl;
fromToken->mImpl = nullptr;
if (mImpl->mTemplateSimplifierPointers)
// cppcheck-suppress shadowFunction - TODO: fix this
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
templateSimplifierPointer->token(this);
}
Expand Down Expand Up @@ -636,6 +639,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[], size_t pattern_l
return false; // shortcut
const char *current = pattern;
const char *end = pattern + pattern_len;
// cppcheck-suppress shadowFunction - TODO: fix this
const char *next = static_cast<const char*>(std::memchr(pattern, ' ', pattern_len));
if (!next)
next = end;
Expand Down Expand Up @@ -781,6 +785,7 @@ nonneg int Token::getStrLength(const Token *tok)
assert(tok->mTokType == eString);

int len = 0;
// cppcheck-suppress shadowFunction - TODO: fix this
const std::string str(getStringLiteral(tok->str()));
std::string::const_iterator it = str.cbegin();
const std::string::const_iterator end = str.cend();
Expand Down Expand Up @@ -808,6 +813,7 @@ nonneg int Token::getStrArraySize(const Token *tok)
{
assert(tok != nullptr);
assert(tok->tokType() == eString);
// cppcheck-suppress shadowFunction - TODO: fix this
const std::string str(getStringLiteral(tok->str()));
int sizeofstring = 1;
for (int i = 0; i < (int)str.size(); i++) {
Expand Down Expand Up @@ -1110,6 +1116,7 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin
tok1 = tok1->previous()->findOpeningBracket();
if (tok1 && Token::Match(tok1->tokAt(-3), "%name% :: %name%")) {
tok1 = tok1->tokAt(-2);
// cppcheck-suppress shadowFunction - TODO: fix this
std::string scope = tok1->strAt(-1);
while (Token::Match(tok1->tokAt(-2), ":: %name%")) {
scope = tok1->strAt(-3) + " :: " + scope;
Expand Down Expand Up @@ -1285,6 +1292,7 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
std::string ret;

unsigned int lineNumber = mImpl->mLineNumber - (options.linenumbers ? 1U : 0U);
// cppcheck-suppress shadowFunction - TODO: fix this
unsigned int fileIndex = options.files ? ~0U : mImpl->mFileIndex;
std::map<int, unsigned int> lineNumbers;
for (const Token *tok = this; tok != end; tok = tok->next()) {
Expand Down Expand Up @@ -1701,13 +1709,15 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
{
std::string outs;

// cppcheck-suppress shadowFunction
int fileIndex = -1;
int line = 0;
if (xml)
outs += " <valueflow>\n";
else
outs += "\n\n##Value flow\n";
for (const Token *tok = this; tok; tok = tok->next()) {
// cppcheck-suppress shadowFunction - TODO: fix this
const auto* const values = tok->mImpl->mValues;
if (!values)
continue;
Expand Down Expand Up @@ -2246,6 +2256,7 @@ void Token::assignProgressValues(Token *tok)

void Token::assignIndexes()
{
// cppcheck-suppress shadowFunction - TODO: fix this
int index = (mPrevious ? mPrevious->mImpl->mIndex : 0) + 1;
for (Token *tok = this; tok; tok = tok->next())
tok->mImpl->mIndex = index++;
Expand Down Expand Up @@ -2283,9 +2294,11 @@ const ::Type* Token::typeOf(const Token* tok, const Token** typeTok)
if (tok->function())
return tok->function()->retType;
if (Token::simpleMatch(tok, "return")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope *scope = tok->scope();
if (!scope)
return nullptr;
// cppcheck-suppress shadowFunction - TODO: fix this
const Function *function = scope->function;
if (!function)
return nullptr;
Expand Down Expand Up @@ -2395,15 +2408,18 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
return {var->typeStartToken(), var->typeEndToken()->next()};
}
if (Token::simpleMatch(tok, "return")) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Scope* scope = tok->scope();
if (!scope)
return {};
// cppcheck-suppress shadowFunction - TODO: fix this
const Function* function = scope->function;
if (!function)
return {};
return { function->retDef, function->returnDefEnd() };
}
if (tok->previous() && tok->previous()->function()) {
// cppcheck-suppress shadowFunction - TODO: fix this
const Function *function = tok->previous()->function();
return {function->retDef, function->returnDefEnd()};
}
Expand Down
1 change: 1 addition & 0 deletions tools/triage/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void MainWindow::findInFilesClicked()
ui->inFilesResult->clear();
const QString text = ui->filterEdit->text();

// cppcheck-suppress shadowFunction - TODO: fix this
QStringList filter;
if (ui->hFilesFilter->isChecked())
filter.append(hFiles);
Expand Down

0 comments on commit e8e6529

Please sign in to comment.