From 8ed20dc47b0b39074577c87db3e0832d1e5a01fc Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 12 Feb 2024 02:34:15 +0100 Subject: [PATCH] fixed `readability-use-std-min-max` clang-tidy warnings --- gui/mainwindow.cpp | 4 +--- gui/resultstree.cpp | 5 +++-- gui/statsdialog.cpp | 5 +++-- gui/threadhandler.cpp | 6 ++---- lib/checkbufferoverrun.cpp | 6 ++---- lib/checkersreport.cpp | 4 ++-- lib/library.cpp | 3 +-- lib/symboldatabase.cpp | 3 +-- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b23a8aeebae1..63e336f18876 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1126,9 +1126,7 @@ QPair MainWindow::getCppcheckSettings() result.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString()); result.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); - if (result.jobs <= 1) { - result.jobs = 1; - } + result.jobs = std::max(result.jobs, 1); Settings::terminate(false); diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 747f06cd6dd8..88d48fe41d49 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -32,6 +32,8 @@ #include "threadhandler.h" #include "xmlreportv2.h" +#include + #include #include #include @@ -616,8 +618,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) if (mContextItem && mApplications->getApplicationCount() > 0 && mContextItem->parent()) { //Create an action for the application int defaultApplicationIndex = mApplications->getDefaultApplication(); - if (defaultApplicationIndex < 0) - defaultApplicationIndex = 0; + defaultApplicationIndex = std::max(defaultApplicationIndex, 0); const Application& app = mApplications->getApplication(defaultApplicationIndex); auto *start = new QAction(app.getName(), &menu); if (multipleSelection) diff --git a/gui/statsdialog.cpp b/gui/statsdialog.cpp index 8790a179d8e0..66a57b2315c2 100644 --- a/gui/statsdialog.cpp +++ b/gui/statsdialog.cpp @@ -22,6 +22,8 @@ #include "projectfile.h" #include "showtypes.h" +#include + #include "ui_statsdialog.h" #include @@ -409,8 +411,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool) s->attachAxis(axisY); if (const auto *ls = dynamic_cast(s)) { for (QPointF p : ls->points()) { - if (p.y() > maxY) - maxY = p.y(); + maxY = std::max(p.y(), maxY); } } } diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index b6fd53d251f0..d69f2db0fedd 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -23,6 +23,7 @@ #include "resultsview.h" #include "settings.h" +#include #include #include #include @@ -92,10 +93,7 @@ void ThreadHandler::check(const Settings &settings) setThreadCount(settings.jobs); mRunningThreadCount = mThreads.size(); - - if (mResults.getFileCount() < mRunningThreadCount) { - mRunningThreadCount = mResults.getFileCount(); - } + mRunningThreadCount = std::min(mResults.getFileCount(), mRunningThreadCount); QStringList addonsAndTools = mAddonsAndTools; for (const std::string& addon: settings.addons) { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 0dbb06562ffc..9b5f238da0ee 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -157,13 +157,11 @@ static int getMinFormatStringOutputLength(const std::vector ¶m if (formatString[i] == 's') { // For strings, the length after the dot "%.2s" will limit // the length of the string. - if (parameterLength > maxLen) - parameterLength = maxLen; + parameterLength = std::min(parameterLength, maxLen); } else { // For integers, the length after the dot "%.2d" can // increase required length - if (tempDigits < maxLen) - tempDigits = maxLen; + tempDigits = std::max(tempDigits, maxLen); } } diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index bff22361d5fa..57da92f99f33 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -22,6 +22,7 @@ #include "errortypes.h" #include "settings.h" +#include #include #include #include @@ -122,8 +123,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const int maxCheckerSize = 0; for (const auto& checkReq: checkers::allCheckers) { const std::string& checker = checkReq.first; - if (checker.size() > maxCheckerSize) - maxCheckerSize = checker.size(); + maxCheckerSize = std::max::size_type>(checker.size(), maxCheckerSize); } for (const auto& checkReq: checkers::allCheckers) { const std::string& checker = checkReq.first; diff --git a/lib/library.cpp b/lib/library.cpp index 05d92c047f02..58c9756c2930 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -1284,8 +1284,7 @@ bool Library::matchArguments(const Token *ftok, const std::string &functionName) int args = 0; int firstOptionalArg = -1; for (const std::pair & argCheck : it->second.argumentChecks) { - if (argCheck.first > args) - args = argCheck.first; + args = std::max(argCheck.first, args); if (argCheck.second.optional && (firstOptionalArg == -1 || firstOptionalArg > argCheck.first)) firstOptionalArg = argCheck.first; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 062e33018467..a12d3804403a 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -1700,8 +1700,7 @@ void SymbolDatabase::createSymbolDatabaseExprIds() // Find highest varId nonneg int maximumVarId = 0; for (const Token* tok = mTokenizer.list.front(); tok; tok = tok->next()) { - if (tok->varId() > maximumVarId) - maximumVarId = tok->varId(); + maximumVarId = std::max(tok->varId(), maximumVarId); } nonneg int id = maximumVarId + 1; // Find incomplete vars that are used in constant context