use more granular suppressions in selfcheck and prefer inline suppressions (#5703)

This commit is contained in:
Oliver Stöneberg 2023-12-01 15:59:01 +01:00 committed by GitHub
parent d6a1a657df
commit 4182f943aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 54 additions and 17 deletions

View File

@ -1,12 +1,9 @@
missingIncludeSystem
shadowFunction
bitwiseOnBoolean
# temporary suppressions - fix the warnings!
simplifyUsing:lib/valueptr.h
varid0:gui/projectfile.cpp
naming-privateMemberVariable:gui/test/cppchecklibrarydata/testcppchecklibrarydata.h
templateInstantiation
symbolDatabaseWarning:*/moc_*.cpp
simplifyUsing:*/moc_*.cpp
@ -19,10 +16,13 @@ functionStatic:*/ui_fileview.h
valueFlowBailout
valueFlowBailoutIncompleteVar
autoNoType
bailoutUninitVar
naming-varname:externals/simplecpp/simplecpp.h
naming-privateMemberVariable:externals/simplecpp/simplecpp.h
# TODO: use more granular suppressions - might expose false positives
*:externals/picojson/*
*:externals/tinyxml2/*
# these warnings need to be addressed upstream
uninitMemberVar:externals/tinyxml2/tinyxml2.h
noExplicitConstructor:externals/tinyxml2/tinyxml2.h
missingOverride:externals/tinyxml2/tinyxml2.h
invalidPrintfArgType_sint:externals/tinyxml2/tinyxml2.h
naming-privateMemberVariable:externals/tinyxml2/tinyxml2.h

View File

@ -643,8 +643,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
}
//Create an action for the application
QAction *recheckSelectedFiles = new QAction(tr("Recheck"), &menu);
QAction *copy = new QAction(tr("Copy"), &menu);
QAction *recheckAction = new QAction(tr("Recheck"), &menu);
QAction *copyAction = new QAction(tr("Copy"), &menu);
QAction *hide = new QAction(tr("Hide"), &menu);
QAction *hideallid = new QAction(tr("Hide all with id"), &menu);
QAction *opencontainingfolder = new QAction(tr("Open containing folder"), &menu);
@ -654,13 +654,13 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
opencontainingfolder->setDisabled(true);
}
if (mThread->isChecking())
recheckSelectedFiles->setDisabled(true);
recheckAction->setDisabled(true);
else
recheckSelectedFiles->setDisabled(false);
recheckAction->setDisabled(false);
menu.addAction(recheckSelectedFiles);
menu.addAction(recheckAction);
menu.addSeparator();
menu.addAction(copy);
menu.addAction(copyAction);
menu.addSeparator();
menu.addAction(hide);
menu.addAction(hideallid);
@ -672,8 +672,8 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
menu.addSeparator();
menu.addAction(opencontainingfolder);
connect(recheckSelectedFiles, SIGNAL(triggered()), this, SLOT(recheckSelectedFiles()));
connect(copy, SIGNAL(triggered()), this, SLOT(copy()));
connect(recheckAction, SIGNAL(triggered()), this, SLOT(recheckAction()));
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyAction()));
connect(hide, SIGNAL(triggered()), this, SLOT(hideResult()));
connect(hideallid, SIGNAL(triggered()), this, SLOT(hideAllIdResult()));
connect(opencontainingfolder, SIGNAL(triggered()), this, SLOT(openContainingFolder()));

View File

@ -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");

View File

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

View File

@ -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] == '-') {
@ -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] == '-') {

View File

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

View File

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

View File

@ -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");

View File

@ -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());

View File

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

View File

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

View File

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

View File

@ -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);
}
@ -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);
}
@ -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;
@ -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();
@ -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++) {
@ -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;
@ -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()) {
@ -1701,6 +1709,7 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
{
std::string outs;
// cppcheck-suppress shadowFunction
int fileIndex = -1;
int line = 0;
if (xml)
@ -1708,6 +1717,7 @@ void Token::printValueFlow(bool xml, std::ostream &out) const
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;
@ -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++;
@ -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;
@ -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()};
}

View File

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