From bfe19af6b208c1a0a833ea503d53e603d7a19079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 18 Oct 2023 10:06:17 +0200 Subject: [PATCH] fixed some "Declaration and assignment can be joined" Rider warnings (#5569) --- gui/projectfile.cpp | 24 ++++++++---------------- gui/resultstree.cpp | 14 ++++++-------- gui/statsdialog.cpp | 3 +-- lib/checknullpointer.cpp | 3 +-- lib/checkstl.cpp | 3 +-- lib/checkunusedvar.cpp | 4 +--- lib/symboldatabase.cpp | 4 +--- lib/token.cpp | 9 +++------ 8 files changed, 22 insertions(+), 42 deletions(-) diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index a0bd1881006..f24f6eece93 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -388,10 +388,9 @@ QString ProjectFile::readString(QXmlStreamReader &reader) void ProjectFile::readIncludeDirs(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; bool allRead = false; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: @@ -426,10 +425,9 @@ void ProjectFile::readIncludeDirs(QXmlStreamReader &reader) void ProjectFile::readDefines(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; bool allRead = false; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read define-elements @@ -463,10 +461,9 @@ void ProjectFile::readDefines(QXmlStreamReader &reader) void ProjectFile::readCheckPaths(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; bool allRead = false; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: @@ -501,10 +498,9 @@ void ProjectFile::readCheckPaths(QXmlStreamReader &reader) void ProjectFile::readExcludes(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; bool allRead = false; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read exclude-elements @@ -547,9 +543,8 @@ void ProjectFile::readExcludes(QXmlStreamReader &reader) void ProjectFile::readVsConfigurations(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read library-elements @@ -611,9 +606,8 @@ void ProjectFile::readPlatform(QXmlStreamReader &reader) void ProjectFile::readSuppressions(QXmlStreamReader &reader) { - QXmlStreamReader::TokenType type; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read library-elements @@ -658,9 +652,8 @@ void ProjectFile::readSuppressions(QXmlStreamReader &reader) void ProjectFile::readTagWarnings(QXmlStreamReader &reader, const QString &tag) { - QXmlStreamReader::TokenType type; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read library-elements @@ -693,10 +686,9 @@ void ProjectFile::readTagWarnings(QXmlStreamReader &reader, const QString &tag) void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[]) { - QXmlStreamReader::TokenType type; bool allRead = false; do { - type = reader.readNext(); + QXmlStreamReader::TokenType type = reader.readNext(); switch (type) { case QXmlStreamReader::StartElement: // Read library-elements diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 8d54380dbb5..49b5e179f5f 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -221,12 +221,11 @@ bool ResultsTree::addErrorItem(const ErrorItem &item) line.file = e.file; line.line = e.line; line.message = line.summary = e.info; - QStandardItem *child_item; - child_item = addBacktraceFiles(stditem, - line, - hide, - ":images/go-down.png", - true); + QStandardItem *child_item = addBacktraceFiles(stditem, + line, + hide, + ":images/go-down.png", + true); if (!child_item) continue; @@ -1140,11 +1139,10 @@ QString ResultsTree::getFilePath(const QStandardItem *target, bool fullPath) target = target->parent()->child(target->row(), 0); QVariantMap data = target->data().toMap(); - QString pathStr; //Replace (file) with filename QString file = data[FILENAME].toString(); - pathStr = QDir::toNativeSeparators(file); + QString pathStr = QDir::toNativeSeparators(file); if (!fullPath) { QFileInfo fi(pathStr); pathStr = fi.fileName(); diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 1cb8464ef5c..1b40ca431ec 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -113,8 +113,7 @@ void StatsDialog::setProject(const ProjectFile* projectFile) } mUI->mLblHistoryFile->setText(tr("File: ") + (statsFile.isEmpty() ? tr("No cppcheck build dir") : statsFile)); if (!statsFile.isEmpty()) { - QChartView *chartView; - chartView = createChart(statsFile, "cppcheck"); + QChartView *chartView = createChart(statsFile, "cppcheck"); mUI->mTabHistory->layout()->addWidget(chartView); if (projectFile->getClangAnalyzer()) { chartView = createChart(statsFile, CLANG_ANALYZER); diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 3d940ab0931..6d680f370c1 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -452,8 +452,7 @@ void CheckNullPointer::nullPointerError(const Token *tok, const std::string &var } else if (value->defaultArg) { reportError(errorPath, Severity::warning, "nullPointerDefaultArg", errmsgdefarg, CWE_NULL_POINTER_DEREFERENCE, inconclusive || value->isInconclusive() ? Certainty::inconclusive : Certainty::normal); } else { - std::string errmsg; - errmsg = std::string(value->isKnown() ? "Null" : "Possible null") + " pointer dereference"; + std::string errmsg = std::string(value->isKnown() ? "Null" : "Possible null") + " pointer dereference"; if (!varname.empty()) errmsg = "$symbol:" + varname + '\n' + errmsg + ": $symbol"; diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index e310ee99c05..fcf32f1f14e 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -2492,8 +2492,7 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* tok, const ValueFlow if (value->condition) { reportError(errorPath, Severity::warning, "derefInvalidIteratorRedundantCheck", errmsgcond, CWE825, (inconclusive || value->isInconclusive()) ? Certainty::inconclusive : Certainty::normal); } else { - std::string errmsg; - errmsg = std::string(value->isKnown() ? "Dereference" : "Possible dereference") + " of an invalid iterator"; + std::string errmsg = std::string(value->isKnown() ? "Dereference" : "Possible dereference") + " of an invalid iterator"; if (!varname.empty()) errmsg = "$symbol:" + varname + '\n' + errmsg + ": $symbol"; diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 8b33b49b590..418ee77e992 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -231,9 +231,7 @@ void Variables::clearAliases(nonneg int varid) if (usage) { // remove usage from all aliases - std::set::const_iterator i; - - for (i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) { + for (std::set::const_iterator i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) { VariableUsage *temp = find(*i); if (temp) diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 22b1e22204e..c58f61c8c31 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -3214,10 +3214,8 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To path.insert(0, ":: "); } - std::list::iterator it1; - // search for match - for (it1 = scopeList.begin(); it1 != scopeList.end(); ++it1) { + for (std::list::iterator it1 = scopeList.begin(); it1 != scopeList.end(); ++it1) { Scope *scope1 = &(*it1); bool match = false; diff --git a/lib/token.cpp b/lib/token.cpp index a395b4b55e6..dcf567e7d74 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1889,8 +1889,7 @@ const ValueFlow::Value * Token::getInvalidValue(const Token *ftok, nonneg int ar if (!mImpl->mValues || !settings) return nullptr; const ValueFlow::Value *ret = nullptr; - std::list::const_iterator it; - for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { + for (std::list::const_iterator it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isImpossible()) continue; if ((it->isIntValue() && !settings->library.isIntArgValid(ftok, argnr, it->intvalue)) || @@ -1916,8 +1915,7 @@ const Token *Token::getValueTokenMinStrSize(const Settings *settings, MathLib::b return nullptr; const Token *ret = nullptr; int minsize = INT_MAX; - std::list::const_iterator it; - for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { + for (std::list::const_iterator it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isTokValue() && it->tokvalue && it->tokvalue->tokType() == Token::eString) { const int size = getStrSize(it->tokvalue, settings); if (!ret || size < minsize) { @@ -1937,8 +1935,7 @@ const Token *Token::getValueTokenMaxStrLength() const return nullptr; const Token *ret = nullptr; int maxlength = 0; - std::list::const_iterator it; - for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { + for (std::list::const_iterator it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) { if (it->isTokValue() && it->tokvalue && it->tokvalue->tokType() == Token::eString) { const int length = getStrLength(it->tokvalue); if (!ret || length > maxlength) {