Skip to content

Commit

Permalink
fixed readability-use-std-min-max clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 27, 2024
1 parent da9cecd commit 8ed20dc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 21 deletions.
4 changes: 1 addition & 3 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,7 @@ QPair<bool,Settings> 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<unsigned int>(result.jobs, 1);

Settings::terminate(false);

Expand Down
5 changes: 3 additions & 2 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "threadhandler.h"
#include "xmlreportv2.h"

#include <algorithm>

#include <QAction>
#include <QApplication>
#include <QClipboard>
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions gui/statsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "projectfile.h"
#include "showtypes.h"

#include <algorithm>

#include "ui_statsdialog.h"

#include <QApplication>
Expand Down Expand Up @@ -409,8 +411,7 @@ QChartView *createChart(const QString &statsFile, const QString &tool)
s->attachAxis(axisY);
if (const auto *ls = dynamic_cast<const QLineSeries*>(s)) {
for (QPointF p : ls->points()) {
if (p.y() > maxY)
maxY = p.y();
maxY = std::max(p.y(), maxY);
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions gui/threadhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "resultsview.h"
#include "settings.h"

#include <algorithm>
#include <string>
#include <unordered_set>
#include <utility>
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,11 @@ static int getMinFormatStringOutputLength(const std::vector<const Token*> &param
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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "errortypes.h"
#include "settings.h"

#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_set>
Expand Down Expand Up @@ -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<std::basic_string<char>::size_type>(checker.size(), maxCheckerSize);
}
for (const auto& checkReq: checkers::allCheckers) {
const std::string& checker = checkReq.first;
Expand Down
3 changes: 1 addition & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,7 @@ bool Library::matchArguments(const Token *ftok, const std::string &functionName)
int args = 0;
int firstOptionalArg = -1;
for (const std::pair<const int, Library::ArgumentChecks> & 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;

Expand Down
3 changes: 1 addition & 2 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8ed20dc

Please sign in to comment.