fixed some "Declaration and assignment can be joined" Rider warnings (#5569)

This commit is contained in:
Oliver Stöneberg 2023-10-18 10:06:17 +02:00 committed by GitHub
parent b40d36a09e
commit bfe19af6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 42 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -231,9 +231,7 @@ void Variables::clearAliases(nonneg int varid)
if (usage) {
// remove usage from all aliases
std::set<nonneg int>::const_iterator i;
for (i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) {
for (std::set<nonneg int>::const_iterator i = usage->_aliases.cbegin(); i != usage->_aliases.cend(); ++i) {
VariableUsage *temp = find(*i);
if (temp)

View File

@ -3214,10 +3214,8 @@ void SymbolDatabase::addClassFunction(Scope **scope, const Token **tok, const To
path.insert(0, ":: ");
}
std::list<Scope>::iterator it1;
// search for match
for (it1 = scopeList.begin(); it1 != scopeList.end(); ++it1) {
for (std::list<Scope>::iterator it1 = scopeList.begin(); it1 != scopeList.end(); ++it1) {
Scope *scope1 = &(*it1);
bool match = false;

View File

@ -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<ValueFlow::Value>::const_iterator it;
for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) {
for (std::list<ValueFlow::Value>::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<ValueFlow::Value>::const_iterator it;
for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) {
for (std::list<ValueFlow::Value>::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<ValueFlow::Value>::const_iterator it;
for (it = mImpl->mValues->begin(); it != mImpl->mValues->end(); ++it) {
for (std::list<ValueFlow::Value>::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) {