Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
643d2e6
Fix #10412 FN useStlAlgorithm with iterators
chrchr-github May 31, 2022
9d58177
Add test
chrchr-github May 31, 2022
2e98abb
Remove whitespace
chrchr-github May 31, 2022
87d62c6
Use %varid%
chrchr-github May 31, 2022
e133b55
Use AST
chrchr-github Jun 1, 2022
84b90a6
Use %comp%
chrchr-github Jun 1, 2022
f534198
Don't warn if iterators are stored
chrchr-github Jun 7, 2022
cfb9e38
Use helper functions
chrchr-github Jun 7, 2022
c83aaf4
Merge
chrchr-github Jun 11, 2022
51e6d24
Only war for unary inc/dec
chrchr-github Jun 11, 2022
29646ec
Fix some useStlAlgorithm warnings
chrchr-github Jun 15, 2022
77b0556
Merge branch 'main' into chr_Fix10412
chrchr-github Jun 15, 2022
bf78399
Don't use auto
chrchr-github Jun 15, 2022
a3dde5c
Format
chrchr-github Jun 15, 2022
19e906c
Enable useStlAlgorithm in selfcheck
chrchr-github Jun 15, 2022
4d7033e
Use STL algo
chrchr-github Jun 15, 2022
3de404c
Format
chrchr-github Jun 20, 2022
0c93bb0
Use STL algo
chrchr-github Jun 20, 2022
aa7abca
Format
chrchr-github Jun 20, 2022
b979bd8
Typo
chrchr-github Jun 20, 2022
e2f6016
Typo
chrchr-github Jun 20, 2022
4548246
Use STL algo
chrchr-github Jun 20, 2022
6545ca6
Don't suggest std::accumulate for containers, where overloaded operat…
chrchr-github Jun 20, 2022
1083aef
Fix compilation, use STL algo
chrchr-github Jun 20, 2022
1548aed
Format
chrchr-github Jun 20, 2022
eab9ce6
Use STL algo
chrchr-github Jun 20, 2022
fa85fe3
Merge
chrchr-github Jun 20, 2022
960ca80
Use std::find_if
chrchr-github Jun 20, 2022
686a998
Use STL algo
chrchr-github Jun 21, 2022
1d2d7b0
Merge branch 'chr_Fix10412' of https://github.com/chrchr-github/cppch…
chrchr-github Jun 21, 2022
a9295c9
Don't use auto
chrchr-github Jun 21, 2022
4408aef
Use STL algo
chrchr-github Jun 21, 2022
843c05c
Fix previous commit
chrchr-github Jun 21, 2022
a4438c4
Use STL algo, format
chrchr-github Jun 22, 2022
6a2b6ff
Format
chrchr-github Jun 22, 2022
7e2f452
Use STL algo, format
chrchr-github Jun 22, 2022
469e359
Don't use auto, format
chrchr-github Jun 22, 2022
b98bfd1
Use STL algo
chrchr-github Jun 22, 2022
712a637
Use STL algo
chrchr-github Jun 22, 2022
d1bc779
Use STL algo
chrchr-github Jun 23, 2022
bf99448
Merge branch 'chr_Fix10412' of https://github.com/chrchr-github/cppch…
chrchr-github Jun 23, 2022
90e67f7
Use STL algo, format, fix FP with container
chrchr-github Jun 23, 2022
8a4d288
Use std::transform, don't suggest std::accumulate for bool
chrchr-github Jun 23, 2022
a1be1a0
Fix build
chrchr-github Jun 23, 2022
a5866b9
Merge
chrchr-github Jul 9, 2022
e94a925
Restore Use STL algo fixes
chrchr-github Jul 9, 2022
be8c9ec
Format
chrchr-github Jul 9, 2022
e9b36ff
Missing include
chrchr-github Jul 9, 2022
5f9b3cb
Merge
chrchr-github Jul 11, 2022
0499ab2
Merge
chrchr-github Oct 10, 2022
e0a09d9
Merge
chrchr-github Oct 10, 2022
5233db3
Fix merge
chrchr-github Oct 10, 2022
192d0b9
Fix/streamline test cases
chrchr-github Oct 10, 2022
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
4 changes: 2 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
for (const std::string &lib : mSettings->project.guiProject.libraries)
mSettings->libraries.emplace_back(lib);

for (const std::string &ignorePath : mSettings->project.guiProject.excludedPaths)
mIgnoredPaths.emplace_back(ignorePath);
const auto& excludedPaths = mSettings->project.guiProject.excludedPaths;
std::copy(excludedPaths.begin(), excludedPaths.end(), std::back_inserter(mIgnoredPaths));

const std::string platform(mSettings->project.guiProject.platform);

Expand Down
27 changes: 11 additions & 16 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <sstream> // IWYU pragma: keep
#include <utility>
#include <vector>
#include <numeric>

#ifdef USE_UNIX_SIGNAL_HANDLING
#include "cppcheckexecutorsig.h"
Expand Down Expand Up @@ -129,14 +130,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
}

// Output a warning for the user if he tries to exclude headers
bool warn = false;
const std::vector<std::string>& ignored = parser.getIgnoredPaths();
for (const std::string &i : ignored) {
if (Path::isHeader(i)) {
warn = true;
break;
}
}
const bool warn = std::any_of(ignored.begin(), ignored.end(), [](const std::string& i) {
return Path::isHeader(i);
});
if (warn) {
std::cout << "cppcheck: filename exclusion does not apply to header (.h and .hpp) files." << std::endl;
std::cout << "cppcheck: Please use --suppress for ignoring results from the header files." << std::endl;
Expand All @@ -154,11 +151,10 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
// filter only for the selected filenames from all project files
std::list<ImportProject::FileSettings> newList;

for (const ImportProject::FileSettings &fsetting : settings.project.fileSettings) {
if (matchglobs(mSettings->fileFilters, fsetting.filename)) {
newList.emplace_back(fsetting);
}
}
const std::list<ImportProject::FileSettings>& fileSettings = settings.project.fileSettings;
std::copy_if(fileSettings.begin(), fileSettings.end(), std::back_inserter(newList), [&](const ImportProject::FileSettings& fs) {
return matchglobs(mSettings->fileFilters, fs.filename);
});
if (!newList.empty())
settings.project.fileSettings = newList;
else {
Expand Down Expand Up @@ -325,10 +321,9 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
// Single process
settings.jointSuppressionReport = true;

std::size_t totalfilesize = 0;
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) {
totalfilesize += i->second;
}
const std::size_t totalfilesize = std::accumulate(mFiles.begin(), mFiles.end(), std::size_t(0), [](std::size_t v, const std::pair<std::string, std::size_t>& f) {
return v + f.second;
});

std::size_t processedsize = 0;
unsigned int c = 0;
Expand Down
12 changes: 6 additions & 6 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
#include "suppressions.h"

#include <algorithm>
#include <numeric>
#include <cerrno>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <functional>
#include <iostream>
#include <list>
#include <sstream> // IWYU pragma: keep
#include <sys/select.h>
#include <sys/wait.h>
#include <unistd.h>
#include <utility>
#include <fcntl.h>


#ifdef __SVR4 // Solaris
#include <sys/loadavg.h>
Expand Down Expand Up @@ -217,10 +218,9 @@ unsigned int ProcessExecutor::check()
unsigned int fileCount = 0;
unsigned int result = 0;

std::size_t totalfilesize = 0;
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) {
totalfilesize += i->second;
}
const std::size_t totalfilesize = std::accumulate(mFiles.begin(), mFiles.end(), std::size_t(0), [](std::size_t v, const std::pair<std::string, std::size_t>& p) {
return v + p.second;
});

std::list<int> rpipes;
std::map<pid_t, std::string> childFile;
Expand Down
13 changes: 7 additions & 6 deletions cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ class ThreadExecutor::SyncLogForwarder : public ErrorLogger
{
public:
explicit SyncLogForwarder(ThreadExecutor &threadExecutor)
: mThreadExecutor(threadExecutor), mProcessedFiles(0), mTotalFiles(0), mProcessedSize(0), mTotalFileSize(0) {
: mThreadExecutor(threadExecutor), mProcessedFiles(0), mTotalFiles(0), mProcessedSize(0) {

mItNextFile = mThreadExecutor.mFiles.begin();
const std::map<std::string, std::size_t>& files = mThreadExecutor.mFiles;
mItNextFile = files.begin();
mItNextFileSettings = mThreadExecutor.mSettings.project.fileSettings.begin();

mTotalFiles = mThreadExecutor.mFiles.size() + mThreadExecutor.mSettings.project.fileSettings.size();
for (std::map<std::string, std::size_t>::const_iterator i = mThreadExecutor.mFiles.begin(); i != mThreadExecutor.mFiles.end(); ++i) {
mTotalFileSize += i->second;
}
mTotalFiles = files.size() + mThreadExecutor.mSettings.project.fileSettings.size();
mTotalFileSize = std::accumulate(files.begin(), files.end(), std::size_t(0), [](std::size_t v, const std::pair<std::string, std::size_t>& p) {
return v + p.second;
});
}

void reportOut(const std::string &outmsg, Color c) override
Expand Down
14 changes: 6 additions & 8 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
continue;

std::list<ErrorMessage::FileLocation> callstack;
for (const QErrorPathItem &path : e.errorPath) {
callstack.emplace_back(path.file.toStdString(), path.info.toStdString(), path.line, path.column);
}
std::transform(e.errorPath.begin(), e.errorPath.end(), std::back_inserter(callstack), [](const QErrorPathItem& path) {
return ErrorMessage::FileLocation(path.file.toStdString(), path.info.toStdString(), path.line, path.column);
});
const std::string f0 = file0.toStdString();
const std::string msg = e.message.toStdString();
const std::string id = e.errorId.toStdString();
Expand All @@ -411,11 +411,9 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS

bool CheckThread::isSuppressed(const Suppressions::ErrorMessage &errorMessage) const
{
for (const Suppressions::Suppression &suppression : mSuppressions) {
if (suppression.isSuppressed(errorMessage))
return true;
}
return false;
return std::any_of(mSuppressions.begin(), mSuppressions.end(), [&](const Suppressions::Suppression& s) {
return s.isSuppressed(errorMessage);
});
}

QString CheckThread::clangCmd()
Expand Down
6 changes: 3 additions & 3 deletions gui/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ void FileList::addExcludeList(const QStringList &paths)
static std::vector<std::string> toStdStringList(const QStringList &stringList)
{
std::vector<std::string> ret;
for (const QString &s : stringList) {
ret.push_back(s.toStdString());
}
std::transform(stringList.begin(), stringList.end(), std::back_inserter(ret), [](const QString& s) {
return s.toStdString();
});
return ret;
}

Expand Down
12 changes: 7 additions & 5 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ int main(int argc, char *argv[])
QSettings* settings = new QSettings("Cppcheck", "Cppcheck-GUI", &app);

// Set data dir..
for (const QString& arg : QApplication::arguments()) {
if (arg.startsWith("--data-dir=")) {
settings->setValue("DATADIR", arg.mid(11));
return 0;
}
const QStringList args = QApplication::arguments();
auto it = std::find_if(args.begin(), args.end(), [](const QString& arg) {
return arg.startsWith("--data-dir=");
});
if (it != args.end()) {
settings->setValue("DATADIR", it->mid(11));
return 0;
}

TranslationHandler* th = new TranslationHandler(&app);
Expand Down
12 changes: 7 additions & 5 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,10 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
mIsLogfileLoaded = false;
if (mProjectFile) {
std::vector<std::string> v;
for (const QString &i : mProjectFile->getExcludedPaths()) {
v.push_back(i.toStdString());
}
const QStringList excluded = mProjectFile->getExcludedPaths();
std::transform(excluded.begin(), excluded.end(), std::back_inserter(v), [](const QString& e) {
return e.toStdString();
});
p.ignorePaths(v);

if (!mProjectFile->getAnalyzeAllVsConfigs()) {
Expand Down Expand Up @@ -554,8 +555,9 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
if (!checkSettings.buildDir.empty()) {
checkSettings.loadSummaries();
std::list<std::string> sourcefiles;
for (const QString& s: fileNames)
sourcefiles.push_back(s.toStdString());
std::transform(fileNames.begin(), fileNames.end(), std::back_inserter(sourcefiles), [](const QString& s) {
return s.toStdString();
});
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, checkSettings.userDefines, checkSettings.project.fileSettings);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
Check::Check(const std::string &aname)
: mTokenizer(nullptr), mSettings(nullptr), mErrorLogger(nullptr), mName(aname)
{
for (std::list<Check*>::iterator i = instances().begin(); i != instances().end(); ++i) {
if ((*i)->name() > aname) {
instances().insert(i, this);
return;
}
}
instances().push_back(this);
auto it = std::find_if(instances().begin(), instances().end(), [&](const Check* i) {
return i->name() > aname;
});
if (it == instances().end())
instances().push_back(this);
else
instances().insert(it, this);
}

void Check::reportError(const ErrorMessage &errmsg)
Expand Down
8 changes: 4 additions & 4 deletions lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ static bool isInScope(const Token * tok, const Scope * scope)
const Scope * tokScope = tok->scope();
if (!tokScope)
return false;
for (const Scope * argScope:tokScope->nestedList) {
if (argScope && argScope->isNestedIn(scope))
return true;
}
if (std::any_of(tokScope->nestedList.begin(), tokScope->nestedList.end(), [&](const Scope* argScope) {
return argScope && argScope->isNestedIn(scope);
}))
return true;
}
return false;
}
Expand Down
Loading