Skip to content

Commit 4182f94

Browse files
authored
use more granular suppressions in selfcheck and prefer inline suppressions (danmar#5703)
1 parent d6a1a65 commit 4182f94

14 files changed

+54
-17
lines changed

.selfcheck_suppressions

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
missingIncludeSystem
2-
shadowFunction
3-
bitwiseOnBoolean
42

53
# temporary suppressions - fix the warnings!
64
simplifyUsing:lib/valueptr.h
75
varid0:gui/projectfile.cpp
86
naming-privateMemberVariable:gui/test/cppchecklibrarydata/testcppchecklibrarydata.h
9-
templateInstantiation
107
symbolDatabaseWarning:*/moc_*.cpp
118
simplifyUsing:*/moc_*.cpp
129

@@ -19,10 +16,13 @@ functionStatic:*/ui_fileview.h
1916
valueFlowBailout
2017
valueFlowBailoutIncompleteVar
2118
autoNoType
22-
bailoutUninitVar
2319

2420
naming-varname:externals/simplecpp/simplecpp.h
2521
naming-privateMemberVariable:externals/simplecpp/simplecpp.h
26-
# TODO: use more granular suppressions - might expose false positives
27-
*:externals/picojson/*
28-
*:externals/tinyxml2/*
22+
23+
# these warnings need to be addressed upstream
24+
uninitMemberVar:externals/tinyxml2/tinyxml2.h
25+
noExplicitConstructor:externals/tinyxml2/tinyxml2.h
26+
missingOverride:externals/tinyxml2/tinyxml2.h
27+
invalidPrintfArgType_sint:externals/tinyxml2/tinyxml2.h
28+
naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h

gui/resultstree.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
643643
}
644644

645645
//Create an action for the application
646-
QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
647-
QAction *copy = new QAction(tr("Copy"), &menu);
646+
QAction *recheckAction = new QAction(tr("Recheck"), &menu);
647+
QAction *copyAction = new QAction(tr("Copy"), &menu);
648648
QAction *hide = new QAction(tr("Hide"), &menu);
649649
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
650650
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
@@ -654,13 +654,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
654654
opencontainingfolder->setDisabled(true);
655655
}
656656
if (mThread->isChecking())
657-
recheckSelectedFiles->setDisabled(true);
657+
recheckAction->setDisabled(true);
658658
else
659-
recheckSelectedFiles->setDisabled(false);
659+
recheckAction->setDisabled(false);
660660

661-
menu.addAction(recheckSelectedFiles);
661+
menu.addAction(recheckAction);
662662
menu.addSeparator();
663-
menu.addAction(copy);
663+
menu.addAction(copyAction);
664664
menu.addSeparator();
665665
menu.addAction(hide);
666666
menu.addAction(hideallid);
@@ -672,8 +672,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
672672
menu.addSeparator();
673673
menu.addAction(opencontainingfolder);
674674

675-
connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles()));
676-
connect(copy, SIGNAL(triggered()), this, SLOT(copy()));
675+
connect(recheckAction, SIGNAL(triggered()), this, SLOT(recheckAction()));
676+
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyAction()));
677677
connect(hide, SIGNAL(triggered()), this, SLOT(hideResult()));
678678
connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult()));
679679
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder()));

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ Check::FileInfo *CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, con
953953

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

lib/checkclass.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, Member
24792479
return false;
24802480
const Token* assignTok = end->next()->astParent();
24812481
if (var && assignTok && assignTok->isAssignmentOp() && assignTok->astOperand1() && assignTok->astOperand1()->variable()) {
2482+
// cppcheck-suppress shadowFunction - TODO: fix this
24822483
const Variable* assignVar = assignTok->astOperand1()->variable();
24832484
if (assignVar->isPointer() && !assignVar->isConst() && var->typeScope()) {
24842485
const auto& funcMap = var->typeScope()->functionMap;

lib/checknullpointer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ static std::string arithmeticTypeString(const Token *tok)
514514

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

533534
void CheckNullPointer::redundantConditionWarning(const Token* tok, const ValueFlow::Value *value, const Token *condition, bool inconclusive)
534535
{
536+
// cppcheck-suppress shadowFunction - TODO: fix this
535537
std::string arithmetic = arithmeticTypeString(tok);
536538
std::string errmsg;
537539
if (tok && tok->str()[0] == '-') {

lib/checkunusedfunctions.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,10 @@ void CheckUnusedFunctions::analyseWholeProgram(const Settings &settings, ErrorLo
459459
}
460460
if (std::strcmp(e2->Name(),"functiondecl") == 0) {
461461
const char* lineNumber = e2->Attribute("lineNumber");
462-
if (lineNumber)
462+
if (lineNumber) {
463+
// cppcheck-suppress templateInstantiation - TODO: fix this - see #11631
463464
decls[functionName] = Location(sourcefile, strToInt<int>(lineNumber));
465+
}
464466
}
465467
}
466468
}

lib/cppcheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer)
10621062
const std::time_t maxTime = mSettings.checksMaxTime > 0 ? std::time(nullptr) + mSettings.checksMaxTime : 0;
10631063

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

1108+
// cppcheck-suppress shadowFunction - TODO: fix this
11071109
for (const Check *check : Check::instances()) {
11081110
if (doUnusedFunctionOnly && dynamic_cast<const CheckUnusedFunctions*>(check) == nullptr)
11091111
continue;
@@ -1735,6 +1737,7 @@ bool CppCheck::analyseWholeProgram()
17351737
ctu.nestedCalls.insert(ctu.nestedCalls.end(), fi2->nestedCalls.cbegin(), fi2->nestedCalls.cend());
17361738
}
17371739
}
1740+
// cppcheck-suppress shadowFunction - TODO: fix this
17381741
for (Check *check : Check::instances())
17391742
errors |= check->analyseWholeProgram(&ctu, mFileInfo, mSettings, *this); // TODO: ctu
17401743
return errors && (mExitCode > 0);
@@ -1785,6 +1788,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
17851788
ctuFileInfo.loadFromXml(e);
17861789
continue;
17871790
}
1791+
// cppcheck-suppress shadowFunction - TODO: fix this
17881792
for (const Check *check : Check::instances()) {
17891793
if (checkClassAttr == check->name())
17901794
fileInfoList.push_back(check->loadFileInfoFromXml(e));
@@ -1796,6 +1800,7 @@ void CppCheck::analyseWholeProgram(const std::string &buildDir, const std::list<
17961800
CTU::maxCtuDepth = mSettings.maxCtuDepth;
17971801

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

lib/errorlogger.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
169169
severity = attr ? severityFromString(attr) : Severity::none;
170170

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

174175
attr = errmsg->Attribute("inconclusive");

lib/fwdanalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const Token *
317317
// ({ .. })
318318
if (hasGccCompoundStatement(parent->astParent()->astOperand2()))
319319
return Result(Result::Type::BAILOUT);
320+
// cppcheck-suppress shadowFunction - TODO: fix this
320321
const bool reassign = isSameExpression(mCpp, false, expr, parent, mLibrary, false, false, nullptr);
321322
if (reassign)
322323
return Result(Result::Type::WRITE, parent->astParent());

lib/library.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,10 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
392392
if (end)
393393
mExecutableBlocks[extension].setEnd(end);
394394
const char * offset = blocknode->Attribute("offset");
395-
if (offset)
395+
if (offset) {
396+
// cppcheck-suppress templateInstantiation - TODO: fix this - see #11631
396397
mExecutableBlocks[extension].setOffset(strToInt<int>(offset));
398+
}
397399
}
398400

399401
else
@@ -706,6 +708,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
706708
mReturnValueType[name] = type;
707709
if (const char *container = functionnode->Attribute("container"))
708710
mReturnValueContainer[name] = strToInt<int>(container);
711+
// cppcheck-suppress shadowFunction - TODO: fix this
709712
if (const char *unknownReturnValues = functionnode->Attribute("unknownValues")) {
710713
if (std::strcmp(unknownReturnValues, "all") == 0) {
711714
std::vector<MathLib::bigint> values{LLONG_MIN, LLONG_MAX};
@@ -1305,6 +1308,7 @@ bool Library::isCompliantValidationExpression(const char* p)
13051308
error |= (*(p + 1) == '-');
13061309
}
13071310
else if (*p == ':') {
1311+
// cppcheck-suppress bitwiseOnBoolean - TODO: fix this
13081312
error |= range | (*(p + 1) == '.');
13091313
range = true;
13101314
has_dot = false;
@@ -1319,6 +1323,7 @@ bool Library::isCompliantValidationExpression(const char* p)
13191323
has_dot = false;
13201324
has_E = false;
13211325
} else if (*p == '.') {
1326+
// cppcheck-suppress bitwiseOnBoolean - TODO: fix this
13221327
error |= has_dot | (!std::isdigit(*(p + 1)));
13231328
has_dot = true;
13241329
} else if (*p == 'E' || *p == 'e') {

lib/symboldatabase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,7 @@ const Type* Variable::smartPointerType() const
23642364
while (Token::Match(typeTok, "%name%|::"))
23652365
typeTok = typeTok->next();
23662366
if (Token::Match(typeTok, "< %name% >")) {
2367+
// cppcheck-suppress shadowFunction - TODO: fix this
23672368
const Scope* scope = typeTok->scope();
23682369
const Type* ptrType{};
23692370
while (scope && !ptrType) {

lib/templatesimplifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,7 @@ bool TemplateSimplifier::matchSpecialization(
29462946
startToken = startToken->previous();
29472947
if (!Token::simpleMatch(startToken, "template <"))
29482948
continue;
2949+
// cppcheck-suppress shadowFunction - TODO: fix this
29492950
std::vector<const Token *> templateParameters;
29502951
getTemplateParametersInDeclaration(startToken->tokAt(2), templateParameters);
29512952

lib/token.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,13 @@ void Token::swapWithNext()
316316
std::swap(mFlags, mNext->mFlags);
317317
std::swap(mImpl, mNext->mImpl);
318318
if (mImpl->mTemplateSimplifierPointers)
319+
// cppcheck-suppress shadowFunction - TODO: fix this
319320
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
320321
templateSimplifierPointer->token(this);
321322
}
322323

323324
if (mNext->mImpl->mTemplateSimplifierPointers)
325+
// cppcheck-suppress shadowFunction - TODO: fix this
324326
for (auto *templateSimplifierPointer : *mNext->mImpl->mTemplateSimplifierPointers) {
325327
templateSimplifierPointer->token(mNext);
326328
}
@@ -341,6 +343,7 @@ void Token::takeData(Token *fromToken)
341343
mImpl = fromToken->mImpl;
342344
fromToken->mImpl = nullptr;
343345
if (mImpl->mTemplateSimplifierPointers)
346+
// cppcheck-suppress shadowFunction - TODO: fix this
344347
for (auto *templateSimplifierPointer : *mImpl->mTemplateSimplifierPointers) {
345348
templateSimplifierPointer->token(this);
346349
}
@@ -636,6 +639,7 @@ bool Token::simpleMatch(const Token *tok, const char pattern[], size_t pattern_l
636639
return false; // shortcut
637640
const char *current = pattern;
638641
const char *end = pattern + pattern_len;
642+
// cppcheck-suppress shadowFunction - TODO: fix this
639643
const char *next = static_cast<const char*>(std::memchr(pattern, ' ', pattern_len));
640644
if (!next)
641645
next = end;
@@ -781,6 +785,7 @@ nonneg int Token::getStrLength(const Token *tok)
781785
assert(tok->mTokType == eString);
782786

783787
int len = 0;
788+
// cppcheck-suppress shadowFunction - TODO: fix this
784789
const std::string str(getStringLiteral(tok->str()));
785790
std::string::const_iterator it = str.cbegin();
786791
const std::string::const_iterator end = str.cend();
@@ -808,6 +813,7 @@ nonneg int Token::getStrArraySize(const Token *tok)
808813
{
809814
assert(tok != nullptr);
810815
assert(tok->tokType() == eString);
816+
// cppcheck-suppress shadowFunction - TODO: fix this
811817
const std::string str(getStringLiteral(tok->str()));
812818
int sizeofstring = 1;
813819
for (int i = 0; i < (int)str.size(); i++) {
@@ -1110,6 +1116,7 @@ Token* Token::insertToken(const std::string& tokenStr, const std::string& origin
11101116
tok1 = tok1->previous()->findOpeningBracket();
11111117
if (tok1 && Token::Match(tok1->tokAt(-3), "%name% :: %name%")) {
11121118
tok1 = tok1->tokAt(-2);
1119+
// cppcheck-suppress shadowFunction - TODO: fix this
11131120
std::string scope = tok1->strAt(-1);
11141121
while (Token::Match(tok1->tokAt(-2), ":: %name%")) {
11151122
scope = tok1->strAt(-3) + " :: " + scope;
@@ -1285,6 +1292,7 @@ std::string Token::stringifyList(const stringifyOptions& options, const std::vec
12851292
std::string ret;
12861293

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

1712+
// cppcheck-suppress shadowFunction
17041713
int fileIndex = -1;
17051714
int line = 0;
17061715
if (xml)
17071716
outs += " <valueflow>\n";
17081717
else
17091718
outs += "\n\n##Value flow\n";
17101719
for (const Token *tok = this; tok; tok = tok->next()) {
1720+
// cppcheck-suppress shadowFunction - TODO: fix this
17111721
const auto* const values = tok->mImpl->mValues;
17121722
if (!values)
17131723
continue;
@@ -2246,6 +2256,7 @@ void Token::assignProgressValues(Token *tok)
22462256

22472257
void Token::assignIndexes()
22482258
{
2259+
// cppcheck-suppress shadowFunction - TODO: fix this
22492260
int index = (mPrevious ? mPrevious->mImpl->mIndex : 0) + 1;
22502261
for (Token *tok = this; tok; tok = tok->next())
22512262
tok->mImpl->mIndex = index++;
@@ -2283,9 +2294,11 @@ const ::Type* Token::typeOf(const Token* tok, const Token** typeTok)
22832294
if (tok->function())
22842295
return tok->function()->retType;
22852296
if (Token::simpleMatch(tok, "return")) {
2297+
// cppcheck-suppress shadowFunction - TODO: fix this
22862298
const Scope *scope = tok->scope();
22872299
if (!scope)
22882300
return nullptr;
2301+
// cppcheck-suppress shadowFunction - TODO: fix this
22892302
const Function *function = scope->function;
22902303
if (!function)
22912304
return nullptr;
@@ -2395,15 +2408,18 @@ std::pair<const Token*, const Token*> Token::typeDecl(const Token* tok, bool poi
23952408
return {var->typeStartToken(), var->typeEndToken()->next()};
23962409
}
23972410
if (Token::simpleMatch(tok, "return")) {
2411+
// cppcheck-suppress shadowFunction - TODO: fix this
23982412
const Scope* scope = tok->scope();
23992413
if (!scope)
24002414
return {};
2415+
// cppcheck-suppress shadowFunction - TODO: fix this
24012416
const Function* function = scope->function;
24022417
if (!function)
24032418
return {};
24042419
return { function->retDef, function->returnDefEnd() };
24052420
}
24062421
if (tok->previous() && tok->previous()->function()) {
2422+
// cppcheck-suppress shadowFunction - TODO: fix this
24072423
const Function *function = tok->previous()->function();
24082424
return {function->retDef, function->returnDefEnd()};
24092425
}

tools/triage/mainwindow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ void MainWindow::findInFilesClicked()
359359
ui->inFilesResult->clear();
360360
const QString text = ui->filterEdit->text();
361361

362+
// cppcheck-suppress shadowFunction - TODO: fix this
362363
QStringList filter;
363364
if (ui->hFilesFilter->isChecked())
364365
filter.append(hFiles);

0 commit comments

Comments
 (0)