Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two types of Clazy warnings #5807

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions gui/codeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <QChar>
#include <QColor>
#include <QCryptographicHash>
#include <QFont>
#include <QFontMetrics>
#include <QKeySequence>
Expand All @@ -37,7 +38,6 @@
#include <QTextCursor>
#include <QTextEdit>
#include <QTextFormat>
#include <QtCore>

class QTextDocument;

Expand Down Expand Up @@ -448,15 +448,14 @@ void CodeEditor::lineNumberAreaPaintEvent(const QPaintEvent *event)
QString CodeEditor::generateStyleString()
{
QString bgcolor = QString("background:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetBGColor.red())
.arg(mWidgetStyle->widgetBGColor.green())
.arg(mWidgetStyle->widgetBGColor.blue());
.arg(mWidgetStyle->widgetBGColor.red(),
mWidgetStyle->widgetBGColor.green(),
mWidgetStyle->widgetBGColor.blue());
QString fgcolor = QString("color:rgb(%1,%2,%3);")
.arg(mWidgetStyle->widgetFGColor.red())
.arg(mWidgetStyle->widgetFGColor.green())
.arg(mWidgetStyle->widgetFGColor.blue());
.arg(mWidgetStyle->widgetFGColor.red(),
mWidgetStyle->widgetFGColor.green(),
mWidgetStyle->widgetFGColor.blue());
QString style = QString("%1 %2")
.arg(bgcolor)
.arg(fgcolor);
.arg(bgcolor, fgcolor);
return style;
}
2 changes: 1 addition & 1 deletion gui/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ QString toFilterString(const QMap<QString,QString>& filters, bool addAllSupporte
// name patterns are our values. The generated filter string list will
// thus be sorted alphabetically over the descriptions.
for (const auto& k: filters.keys()) {
entries << QString("%1 (%2)").arg(k).arg(filters.value(k));
entries << QString("%1 (%2)").arg(k, filters.value(k));
}

return entries.join(";;");
Expand Down
4 changes: 2 additions & 2 deletions gui/compliancereportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDialogButtonBox>
#include <QDir>
#include <QFile>
Expand All @@ -52,7 +53,6 @@
#include <QStringList>
#include <QTemporaryFile>
#include <QTextStream>
#include <QtCore>

static void addHeaders(const QString& file1, QSet<QString> &allFiles) {
if (allFiles.contains(file1))
Expand Down Expand Up @@ -170,7 +170,7 @@ void ComplianceReportDialog::save()
} catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical,
tr("Save compliance report"),
tr("Failed to import '%1' (%2), can not show files in compliance report").arg(prjfile).arg(QString::fromStdString(e.errorMessage)),
tr("Failed to import '%1' (%2), can not show files in compliance report").arg(prjfile, QString::fromStdString(e.errorMessage)),
QMessageBox::Ok,
this);
msg.exec();
Expand Down
4 changes: 2 additions & 2 deletions gui/cppchecklibrarydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, c
{
throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'")
.arg(xmlReader.lineNumber())
.arg(attributeName)
.arg(xmlReader.name().toString()).toStdString());
.arg(attributeName, xmlReader.name().toString())
.toStdString());
}

static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)
Expand Down
4 changes: 2 additions & 2 deletions gui/csvreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void CsvReport::writeError(const ErrorItem &error)
*/

const QString file = QDir::toNativeSeparators(error.errorPath.back().file);
QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line);
line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity)).arg(error.errorId).arg(error.summary);
QString line = QString("%1,%2,").arg(file, error.errorPath.back().line);
line += QString("%1,%2,%3").arg(GuiSeverity::toString(error.severity), error.errorId, error.summary);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
mTxtWriter << line << Qt::endl;
#else
Expand Down
2 changes: 1 addition & 1 deletion gui/librarydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void LibraryDialog::openCfg()
if (!errmsg.isNull()) {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
tr("Failed to load %1. %2.").arg(selectedFile).arg(errmsg),
tr("Failed to load %1. %2.").arg(selectedFile, errmsg),
QMessageBox::Ok,
this);
msg.exec();
Expand Down
1 change: 0 additions & 1 deletion gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QString>
#include <QStringList>
#include <QVariant>
#include <QtCore>


static void ShowUsage();
Expand Down
12 changes: 6 additions & 6 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
const Library::Error error = loadLibrary(library, filename);
if (error.errorcode != Library::ErrorCode::OK) {
if (error.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT) {
QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename).arg(error.reason.c_str()));
QMessageBox::information(this, tr("Information"), tr("The library '%1' contains unknown elements:\n%2").arg(filename, error.reason.c_str()));
return true;
}

Expand Down Expand Up @@ -899,7 +899,7 @@ bool MainWindow::tryLoadLibrary(Library *library, const QString& filename)
}
if (!error.reason.empty())
errmsg += " '" + QString::fromStdString(error.reason) + "'";
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library '%1'.\n%2").arg(filename).arg(errmsg));
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library '%1'.\n%2").arg(filename, errmsg));
return false;
}
return true;
Expand Down Expand Up @@ -958,7 +958,7 @@ Settings MainWindow::getCppcheckSettings()
{
const QString cfgErr = QString::fromStdString(result.loadCppcheckCfg());
if (!cfgErr.isEmpty())
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2").arg("cppcheck.cfg").arg(cfgErr));
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1 - %2").arg("cppcheck.cfg", cfgErr));

const auto cfgAddons = result.addons;
result.addons.clear();
Expand Down Expand Up @@ -1787,7 +1787,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
if (!errorMessage.isEmpty()) {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
tr("Failed to import '%1': %2\n\nAnalysis is stopped.").arg(prjfile).arg(errorMessage),
tr("Failed to import '%1': %2\n\nAnalysis is stopped.").arg(prjfile, errorMessage),
QMessageBox::Ok,
this);
msg.exec();
Expand All @@ -1796,7 +1796,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check
} catch (InternalError &e) {
QMessageBox msg(QMessageBox::Critical,
tr("Cppcheck"),
tr("Failed to import '%1' (%2), analysis is stopped").arg(prjfile).arg(QString::fromStdString(e.errorMessage)),
tr("Failed to import '%1' (%2), analysis is stopped").arg(prjfile, QString::fromStdString(e.errorMessage)),
QMessageBox::Ok,
this);
msg.exec();
Expand Down Expand Up @@ -2100,7 +2100,7 @@ void MainWindow::replyFinished(QNetworkReply *reply) {
}
mUI->mButtonHideInformation->setVisible(true);
mUI->mLabelInformation->setVisible(true);
mUI->mLabelInformation->setText(tr("New version available: %1. %2").arg(str.trimmed()).arg(install));
mUI->mLabelInformation->setText(tr("New version available: %1. %2").arg(str.trimmed(), install));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gui/printablereport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void PrintableReport::writeError(const ErrorItem &error)
{
const QString file = QDir::toNativeSeparators(error.errorPath.back().file);
QString line = QString("%1,%2,").arg(file).arg(error.errorPath.back().line);
line += QString("%1,%2").arg(GuiSeverity::toString(error.severity)).arg(error.summary);
line += QString("%1,%2").arg(GuiSeverity::toString(error.severity), error.summary);

mFormattedReport += line;
mFormattedReport += "\n";
Expand Down
1 change: 0 additions & 1 deletion gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include <QSize>
#include <QSpinBox>
#include <QVariant>
#include <QtCore>

static constexpr char ADDON_MISRA[] = "misra";
static constexpr char CODING_STANDARD_MISRA_C_2023[] = "misra-c-2023";
Expand Down
2 changes: 1 addition & 1 deletion gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ void ResultsTree::startApplication(const QStandardItem *target, int application)
}
#endif // Q_OS_WIN

const QString cmdLine = QString("%1 %2").arg(program).arg(params);
const QString cmdLine = QString("%1 %2").arg(program, params);

// this is reported as deprecated in Qt 5.15.2 but no longer in Qt 6
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
Expand Down
2 changes: 1 addition & 1 deletion gui/resultsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void ResultsView::updateDetails(const QModelIndex &index)

const QString file0 = data["file0"].toString();
if (!file0.isEmpty() && Path::isHeader(data["file"].toString().toStdString()))
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by")).arg(QDir::toNativeSeparators(file0));
formattedMsg += QString("\n\n%1: %2").arg(tr("First included by"), QDir::toNativeSeparators(file0));

if (data["cwe"].toInt() > 0)
formattedMsg.prepend("CWE: " + QString::number(data["cwe"].toInt()) + "\n");
Expand Down
86 changes: 43 additions & 43 deletions gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ void StatsDialog::pdfExport()
"<font color=\"blue\"><h3>%9 : %10</h3></font>\n"
"<font color=\"blue\"><h3>%11 : %12</h3></font>\n"
"<font color=\"purple\"><h3>%13 : %14</h3></font>\n")
.arg(tr("Statistics"))
.arg(QDate::currentDate().toString("dd.MM.yyyy"))
.arg(tr("Errors"))
.arg(tr("Statistics"),
QDate::currentDate().toString("dd.MM.yyyy"),
tr("Errors"))
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(tr("Warnings"))
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))
Expand Down Expand Up @@ -246,31 +246,31 @@ void StatsDialog::copyToClipboard()
"\t%8:\t%9\n"
"\t%10:\t%11\n"
)
.arg(projSettings)
.arg(project)
.arg(mUI->mProject->text())
.arg(paths)
.arg(mUI->mPaths->text())
.arg(incPaths)
.arg(mUI->mIncludePaths->text())
.arg(defines)
.arg(mUI->mDefines->text())
.arg(undefines)
.arg(mUI->mUndefines->text());
.arg(projSettings,
project,
mUI->mProject->text(),
paths,
mUI->mPaths->text(),
incPaths,
mUI->mIncludePaths->text(),
defines)
.arg(mUI->mDefines->text(),
undefines,
mUI->mUndefines->text());

const QString previous = QString(
"%1\n"
"\t%2:\t%3\n"
"\t%4:\t%5\n"
"\t%6:\t%7\n"
)
.arg(prevScan)
.arg(selPath)
.arg(mUI->mPath->text())
.arg(numFiles)
.arg(mUI->mNumberOfFilesScanned->text())
.arg(duration)
.arg(mUI->mScanDuration->text());
.arg(prevScan,
selPath,
mUI->mPath->text(),
numFiles,
mUI->mNumberOfFilesScanned->text(),
duration,
mUI->mScanDuration->text());

const QString statistics = QString(
"%1\n"
Expand All @@ -281,8 +281,8 @@ void StatsDialog::copyToClipboard()
"\t%10:\t%11\n"
"\t%12:\t%13\n"
)
.arg(stats)
.arg(errors)
.arg(stats,
errors)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(warnings)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))
Expand All @@ -308,17 +308,17 @@ void StatsDialog::copyToClipboard()
" <tr><th>%10:</th><td>%11</td></tr>\n"
"</table>\n"
)
.arg(projSettings)
.arg(project)
.arg(mUI->mProject->text())
.arg(paths)
.arg(mUI->mPaths->text())
.arg(incPaths)
.arg(mUI->mIncludePaths->text())
.arg(defines)
.arg(mUI->mDefines->text())
.arg(undefines)
.arg(mUI->mUndefines->text());
.arg(projSettings,
project,
mUI->mProject->text(),
paths,
mUI->mPaths->text(),
incPaths,
mUI->mIncludePaths->text(),
defines)
.arg(mUI->mDefines->text(),
undefines,
mUI->mUndefines->text());

const QString htmlPrevious = QString(
"<h3>%1</h3>\n"
Expand All @@ -328,13 +328,13 @@ void StatsDialog::copyToClipboard()
" <tr><th>%6:</th><td>%7</td></tr>\n"
"</table>\n"
)
.arg(prevScan)
.arg(selPath)
.arg(mUI->mPath->text())
.arg(numFiles)
.arg(mUI->mNumberOfFilesScanned->text())
.arg(duration)
.arg(mUI->mScanDuration->text());
.arg(prevScan,
selPath,
mUI->mPath->text(),
numFiles,
mUI->mNumberOfFilesScanned->text(),
duration,
mUI->mScanDuration->text());

const QString htmlStatistics = QString(
"<h3>%1</h3>\n"
Expand All @@ -346,8 +346,8 @@ void StatsDialog::copyToClipboard()
" <tr><th>%12:</th><td>%13</td></tr>\n"
"</table>\n"
)
.arg(stats)
.arg(errors)
.arg(stats,
errors)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowErrors))
.arg(warnings)
.arg(mStatistics->getCount(CPPCHECK,ShowTypes::ShowWarnings))
Expand Down
Loading