From 9b1d05c32b23314e33a2c4cc91f7e27947129a59 Mon Sep 17 00:00:00 2001 From: William Jakobsson <50847546+wjakobsson@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:54:00 +0200 Subject: [PATCH 1/5] Fix recheck --- gui/mainwindow.cpp | 23 ++++++++++++++--------- gui/mainwindow.h | 12 ++++++++---- gui/resultstree.cpp | 15 +++++++++++++-- gui/resultstree.h | 6 ++++++ lib/analyzerinfo.cpp | 42 +++++++++++++++++++++++++++++++++++++----- lib/analyzerinfo.h | 5 +++-- 6 files changed, 81 insertions(+), 22 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 31f124bc5b0..d51517ffe6a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -162,7 +162,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : connect(mUI->mActionAnalyzeFiles, &QAction::triggered, this, &MainWindow::analyzeFiles); connect(mUI->mActionAnalyzeDirectory, &QAction::triggered, this, &MainWindow::analyzeDirectory); connect(mUI->mActionSettings, &QAction::triggered, this, &MainWindow::programSettings); - connect(mUI->mActionClearResults, &QAction::triggered, this, &MainWindow::clearResults); + connect(mUI->mActionClearResults, &QAction::triggered, this, [this]() { clearResults(); }); connect(mUI->mActionOpenXML, &QAction::triggered, this, &MainWindow::openResults); connect(mUI->mActionShowStyle, &QAction::toggled, this, &MainWindow::showStyle); @@ -573,7 +573,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo }); } - clearResults(); + clearResults(recheckFiles); mIsLogfileLoaded = false; if (mProjectFile) { @@ -619,7 +619,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo if (!checkSettings.buildDir.empty()) { checkSettings.loadSummaries(); std::list sourcefiles; - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings, !recheckFiles.isEmpty()); } //mThread->SetanalyzeProject(true); @@ -638,7 +638,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo mUI->mResults->setCheckSettings(checkSettings); } -void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, const bool checkConfig) +void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, const bool checkConfig, const bool partialRecheck) { if (files.isEmpty()) return; @@ -648,7 +648,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c if (!getCppcheckSettings(checkSettings, *supprs)) return; - clearResults(); + clearResults(partialRecheck ? files : QStringList()); mIsLogfileLoaded = false; FileList pathList; @@ -660,7 +660,6 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c } QStringList fileNames = pathList.getFileList(); - mUI->mResults->clear(true); mUI->mResults->setResultsSource(ResultsTree::ResultsSource::Analysis); mThread->clearFiles(); @@ -701,7 +700,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c std::transform(fileNames.cbegin(), fileNames.cend(), std::back_inserter(sourcefiles), [](const QString& s) { return s.toStdString(); }); - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}, partialRecheck); } mThread->setCheckFiles(true); @@ -1445,8 +1444,14 @@ void MainWindow::reAnalyze(bool all) mUI->mResults->setCheckSettings(checkSettings); } -void MainWindow::clearResults() +void MainWindow::clearResults(const QStringList& selectedFiles) { + if (!selectedFiles.isEmpty()) { + mUI->mResults->clear(false); + for (QString f : selectedFiles) + mUI->mResults->clearRecheckFile(f); + return; + } if (mProjectFile && !mProjectFile->getBuildDir().isEmpty()) { QDir dir(QFileInfo(mProjectFile->getFilename()).absolutePath() + '/' + mProjectFile->getBuildDir()); for (const QString& f: dir.entryList(QDir::Files)) { @@ -1978,7 +1983,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringLis if (paths.isEmpty()) { paths << mCurrentDirectory; } - doAnalyzeFiles(paths, checkLib, checkConfig); + doAnalyzeFiles(paths, checkLib, checkConfig, !recheckFiles.isEmpty()); } void MainWindow::newProjectFile() diff --git a/gui/mainwindow.h b/gui/mainwindow.h index c654a2c94f0..e3c727ae297 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -107,8 +107,11 @@ public slots: /** @brief Slot to reanalyze modified files */ void reAnalyzeModified(); - /** @brief Slot to clear all search results */ - void clearResults(); + /** + * @brief Slot to clear all search results or selected + * @param selectedFiles list to clear, leave empty for all + */ + void clearResults(const QStringList& selectedFiles = QStringList()); /** @brief Slot to open XML report file */ void openResults(); @@ -309,7 +312,7 @@ private slots: * @param checkLib Flag to indicate if library should be checked * @param checkConfig Flag to indicate if the configuration should be checked. */ - void doAnalyzeProject(ImportProject p, bool checkLib = false, bool checkConfig = false, const QStringList& recheckFiles = QStringList()); + void doAnalyzeProject(ImportProject p, bool checkLib = false, bool checkConfig = false, const QStringList &recheckFiles = QStringList()); /** * @brief Analyze all files specified in parameter files @@ -317,8 +320,9 @@ private slots: * @param files List of files and/or directories to analyze * @param checkLib Flag to indicate if library should be checked * @param checkConfig Flag to indicate if the configuration should be checked. + * @param partialRecheck Flag to indicate a partial recheck. */ - void doAnalyzeFiles(const QStringList &files, bool checkLib = false, bool checkConfig = false); + void doAnalyzeFiles(const QStringList &files, bool checkLib = false, bool checkConfig = false, const bool partialRecheck = false); /** * @brief Get our default cppcheck settings and read project file. diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index ed8b3c7412e..77c1e37f4b1 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -427,7 +427,7 @@ void ResultsTree::clear(const QString &filename) if (stripped == fileItem->text() || filename == fileItem->errorItem->file0) { - mErrorList.removeAll(fileItem->errorItem->toString()); + removeFileErrorsFromErrorList(fileItem); mModel->removeRow(i); break; } @@ -445,7 +445,7 @@ void ResultsTree::clearRecheckFile(const QString &filename) QString storedfile = fileItem->getErrorPathItem().file; storedfile = ((!mCheckPath.isEmpty() && storedfile.startsWith(mCheckPath)) ? storedfile.mid(mCheckPath.length() + 1) : storedfile); if (actualfile == storedfile) { - mErrorList.removeAll(fileItem->errorItem->toString()); + removeFileErrorsFromErrorList(fileItem); mModel->removeRow(i); break; } @@ -1132,6 +1132,16 @@ void ResultsTree::saveErrors(Report *report, const ResultItem *fileItem) const } } +void ResultsTree::removeFileErrorsFromErrorList(const ResultItem *fileItem) +{ + for (int i{0}; i < fileItem->rowCount(); ++i) { + const auto *errorItem = dynamic_cast(fileItem->child(i, COLUMN_FILE)); + if (errorItem && errorItem->errorItem) + mErrorList.removeAll(errorItem->errorItem->toString()); + } + mErrorList.removeAll(fileItem->errorItem->toString()); +} + void ResultsTree::updateFromOldReport(const QString &filename) { showColumn(COLUMN_SINCE_DATE); @@ -1195,6 +1205,7 @@ void ResultsTree::updateSettings(bool showFullPath, void ResultsTree::setCheckDirectory(const QString &dir) { mCheckPath = dir; + refreshFilePaths(); } const QString& ResultsTree::getCheckDirectory() const diff --git a/gui/resultstree.h b/gui/resultstree.h index 23fe5567ed9..b0634e96396 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -356,6 +356,12 @@ protected slots: */ void saveErrors(Report *report, const ResultItem *fileItem) const; + /** + * @brief Remove all errors of a file item from the duplicate-check list + * @param fileItem Item whose errors to remove + */ + void removeFileErrorsFromErrorList(const ResultItem *fileItem); + /** * @brief Convert a severity string to a icon filename * diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 36803b897b1..5c3c0bb8bec 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -24,10 +24,12 @@ #include "utils.h" #include +#include #include #include #include #include +#include #include #include #include @@ -51,18 +53,48 @@ static std::string getFilename(const std::string &fullpath) return fullpath.substr(pos1,pos2); } -void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings) +void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge) { const std::string filesTxt(buildDir + "/files.txt"); + + std::string keptLines; + std::map fileCount; + + if (merge) { + std::set current; + for (const std::string &f : sourcefiles) + current.insert(Path::simplifyPath(f)); + for (const FileSettings &fs : fileSettings) + current.insert(Path::simplifyPath(fs.filename())); + + std::ifstream fin(filesTxt); + std::string line; + while (std::getline(fin, line)) { + Info info; + if (!info.parse(line)) + continue; + if (current.count(info.sourceFile)) + continue; + keptLines += line + '\n'; + + const std::string::size_type dotA = info.afile.rfind(".a"); + if (dotA != std::string::npos) { + const std::string base = info.afile.substr(0, dotA); + const unsigned int n = std::strtoul(info.afile.c_str() + dotA + 2, nullptr, 10); + unsigned int &count = fileCount[base]; + count = std::max(count, n); + } + } + } + std::ofstream fout(filesTxt); - fout << getFilesTxt(sourcefiles, fileSettings); + fout << keptLines; + fout << getFilesTxt(sourcefiles, fileSettings, fileCount); } -std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings) { +std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount) { std::ostringstream ret; - std::map fileCount; - for (const std::string &f : sourcefiles) { const std::string afile = getFilename(f); ret << afile << ".a" << (++fileCount[afile]) << sep << sep << sep << Path::simplifyPath(f) << '\n'; diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index 75674a22f82..4f7a1a72a39 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -27,6 +27,7 @@ #include #include #include +#include #include class ErrorMessage; @@ -57,7 +58,7 @@ class CPPCHECKLIB AnalyzerInformation { public: ~AnalyzerInformation(); - static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings); + static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge = false); /** Close current TU.analyzerinfo file */ void close(); @@ -85,7 +86,7 @@ class CPPCHECKLIB AnalyzerInformation { static std::string processFilesTxt(const std::string& buildDir, const std::function& handler, bool debug = false); protected: - static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings); + static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount = {}); static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId); From a71bb66e60e03229984080e80f2ce108a900c567 Mon Sep 17 00:00:00 2001 From: William Jakobsson <50847546+wjakobsson@users.noreply.github.com> Date: Mon, 6 Jul 2026 13:31:45 +0200 Subject: [PATCH 2/5] nits --- gui/mainwindow.cpp | 6 +++--- gui/mainwindow.h | 2 +- lib/analyzerinfo.cpp | 42 +++++------------------------------------- lib/analyzerinfo.h | 5 ++--- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d51517ffe6a..73f90558b1f 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -619,7 +619,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo if (!checkSettings.buildDir.empty()) { checkSettings.loadSummaries(); std::list sourcefiles; - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings, !recheckFiles.isEmpty()); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings); } //mThread->SetanalyzeProject(true); @@ -700,7 +700,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c std::transform(fileNames.cbegin(), fileNames.cend(), std::back_inserter(sourcefiles), [](const QString& s) { return s.toStdString(); }); - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}, partialRecheck); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}); } mThread->setCheckFiles(true); @@ -1448,7 +1448,7 @@ void MainWindow::clearResults(const QStringList& selectedFiles) { if (!selectedFiles.isEmpty()) { mUI->mResults->clear(false); - for (QString f : selectedFiles) + for (const QString& f : selectedFiles) mUI->mResults->clearRecheckFile(f); return; } diff --git a/gui/mainwindow.h b/gui/mainwindow.h index e3c727ae297..f632598cccb 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -322,7 +322,7 @@ private slots: * @param checkConfig Flag to indicate if the configuration should be checked. * @param partialRecheck Flag to indicate a partial recheck. */ - void doAnalyzeFiles(const QStringList &files, bool checkLib = false, bool checkConfig = false, const bool partialRecheck = false); + void doAnalyzeFiles(const QStringList &files, bool checkLib = false, bool checkConfig = false, bool partialRecheck = false); /** * @brief Get our default cppcheck settings and read project file. diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 5c3c0bb8bec..36803b897b1 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -24,12 +24,10 @@ #include "utils.h" #include -#include #include #include #include #include -#include #include #include #include @@ -53,48 +51,18 @@ static std::string getFilename(const std::string &fullpath) return fullpath.substr(pos1,pos2); } -void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge) +void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings) { const std::string filesTxt(buildDir + "/files.txt"); - - std::string keptLines; - std::map fileCount; - - if (merge) { - std::set current; - for (const std::string &f : sourcefiles) - current.insert(Path::simplifyPath(f)); - for (const FileSettings &fs : fileSettings) - current.insert(Path::simplifyPath(fs.filename())); - - std::ifstream fin(filesTxt); - std::string line; - while (std::getline(fin, line)) { - Info info; - if (!info.parse(line)) - continue; - if (current.count(info.sourceFile)) - continue; - keptLines += line + '\n'; - - const std::string::size_type dotA = info.afile.rfind(".a"); - if (dotA != std::string::npos) { - const std::string base = info.afile.substr(0, dotA); - const unsigned int n = std::strtoul(info.afile.c_str() + dotA + 2, nullptr, 10); - unsigned int &count = fileCount[base]; - count = std::max(count, n); - } - } - } - std::ofstream fout(filesTxt); - fout << keptLines; - fout << getFilesTxt(sourcefiles, fileSettings, fileCount); + fout << getFilesTxt(sourcefiles, fileSettings); } -std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount) { +std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings) { std::ostringstream ret; + std::map fileCount; + for (const std::string &f : sourcefiles) { const std::string afile = getFilename(f); ret << afile << ".a" << (++fileCount[afile]) << sep << sep << sep << Path::simplifyPath(f) << '\n'; diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index 4f7a1a72a39..75674a22f82 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -27,7 +27,6 @@ #include #include #include -#include #include class ErrorMessage; @@ -58,7 +57,7 @@ class CPPCHECKLIB AnalyzerInformation { public: ~AnalyzerInformation(); - static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge = false); + static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings); /** Close current TU.analyzerinfo file */ void close(); @@ -86,7 +85,7 @@ class CPPCHECKLIB AnalyzerInformation { static std::string processFilesTxt(const std::string& buildDir, const std::function& handler, bool debug = false); protected: - static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount = {}); + static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings); static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId); From e782b686acdf24dd271d745e1449c50be1b47de6 Mon Sep 17 00:00:00 2001 From: William Jakobsson <50847546+wjakobsson@users.noreply.github.com> Date: Mon, 6 Jul 2026 14:29:37 +0200 Subject: [PATCH 3/5] nits --- gui/mainwindow.cpp | 4 +++- gui/mainwindow.h | 2 +- gui/resultstree.cpp | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 73f90558b1f..a1756d65f18 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -162,7 +162,9 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : connect(mUI->mActionAnalyzeFiles, &QAction::triggered, this, &MainWindow::analyzeFiles); connect(mUI->mActionAnalyzeDirectory, &QAction::triggered, this, &MainWindow::analyzeDirectory); connect(mUI->mActionSettings, &QAction::triggered, this, &MainWindow::programSettings); - connect(mUI->mActionClearResults, &QAction::triggered, this, [this]() { clearResults(); }); + connect(mUI->mActionClearResults, &QAction::triggered, this, [this]() { + clearResults(); + }); connect(mUI->mActionOpenXML, &QAction::triggered, this, &MainWindow::openResults); connect(mUI->mActionShowStyle, &QAction::toggled, this, &MainWindow::showStyle); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index f632598cccb..72b11c49ec4 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -110,7 +110,7 @@ public slots: /** * @brief Slot to clear all search results or selected * @param selectedFiles list to clear, leave empty for all - */ + */ void clearResults(const QStringList& selectedFiles = QStringList()); /** @brief Slot to open XML report file */ diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 77c1e37f4b1..408866fc2ef 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -1139,7 +1139,6 @@ void ResultsTree::removeFileErrorsFromErrorList(const ResultItem *fileItem) if (errorItem && errorItem->errorItem) mErrorList.removeAll(errorItem->errorItem->toString()); } - mErrorList.removeAll(fileItem->errorItem->toString()); } void ResultsTree::updateFromOldReport(const QString &filename) From 563c7b4b0abe3928d4fca07a5a6da9ed51e149f2 Mon Sep 17 00:00:00 2001 From: William Jakobsson <50847546+wjakobsson@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:32:10 +0200 Subject: [PATCH 4/5] small fix --- gui/mainwindow.cpp | 4 ++-- lib/analyzerinfo.cpp | 42 +++++++++++++++++++++++++++++++++++++----- lib/analyzerinfo.h | 5 +++-- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index a1756d65f18..ed0c44885df 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -621,7 +621,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLib, const bo if (!checkSettings.buildDir.empty()) { checkSettings.loadSummaries(); std::list sourcefiles; - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, p.fileSettings, !recheckFiles.isEmpty()); } //mThread->SetanalyzeProject(true); @@ -702,7 +702,7 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLib, c std::transform(fileNames.cbegin(), fileNames.cend(), std::back_inserter(sourcefiles), [](const QString& s) { return s.toStdString(); }); - AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}); + AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, {}, partialRecheck); } mThread->setCheckFiles(true); diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 36803b897b1..5c3c0bb8bec 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -24,10 +24,12 @@ #include "utils.h" #include +#include #include #include #include #include +#include #include #include #include @@ -51,18 +53,48 @@ static std::string getFilename(const std::string &fullpath) return fullpath.substr(pos1,pos2); } -void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings) +void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge) { const std::string filesTxt(buildDir + "/files.txt"); + + std::string keptLines; + std::map fileCount; + + if (merge) { + std::set current; + for (const std::string &f : sourcefiles) + current.insert(Path::simplifyPath(f)); + for (const FileSettings &fs : fileSettings) + current.insert(Path::simplifyPath(fs.filename())); + + std::ifstream fin(filesTxt); + std::string line; + while (std::getline(fin, line)) { + Info info; + if (!info.parse(line)) + continue; + if (current.count(info.sourceFile)) + continue; + keptLines += line + '\n'; + + const std::string::size_type dotA = info.afile.rfind(".a"); + if (dotA != std::string::npos) { + const std::string base = info.afile.substr(0, dotA); + const unsigned int n = std::strtoul(info.afile.c_str() + dotA + 2, nullptr, 10); + unsigned int &count = fileCount[base]; + count = std::max(count, n); + } + } + } + std::ofstream fout(filesTxt); - fout << getFilesTxt(sourcefiles, fileSettings); + fout << keptLines; + fout << getFilesTxt(sourcefiles, fileSettings, fileCount); } -std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings) { +std::string AnalyzerInformation::getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount) { std::ostringstream ret; - std::map fileCount; - for (const std::string &f : sourcefiles) { const std::string afile = getFilename(f); ret << afile << ".a" << (++fileCount[afile]) << sep << sep << sep << Path::simplifyPath(f) << '\n'; diff --git a/lib/analyzerinfo.h b/lib/analyzerinfo.h index 75674a22f82..4f7a1a72a39 100644 --- a/lib/analyzerinfo.h +++ b/lib/analyzerinfo.h @@ -27,6 +27,7 @@ #include #include #include +#include #include class ErrorMessage; @@ -57,7 +58,7 @@ class CPPCHECKLIB AnalyzerInformation { public: ~AnalyzerInformation(); - static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings); + static void writeFilesTxt(const std::string &buildDir, const std::list &sourcefiles, const std::list &fileSettings, bool merge = false); /** Close current TU.analyzerinfo file */ void close(); @@ -85,7 +86,7 @@ class CPPCHECKLIB AnalyzerInformation { static std::string processFilesTxt(const std::string& buildDir, const std::function& handler, bool debug = false); protected: - static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings); + static std::string getFilesTxt(const std::list &sourcefiles, const std::list &fileSettings, std::map fileCount = {}); static std::string getAnalyzerInfoFileFromFilesTxt(std::istream& filesTxt, const std::string &sourcefile, const std::string &cfg, size_t fsFileId); From 269d2a409443398618a017780f81937e5965e1ac Mon Sep 17 00:00:00 2001 From: William Jakobsson <50847546+wjakobsson@users.noreply.github.com> Date: Mon, 6 Jul 2026 15:55:03 +0200 Subject: [PATCH 5/5] fix github warning --- lib/analyzerinfo.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/analyzerinfo.cpp b/lib/analyzerinfo.cpp index 5c3c0bb8bec..cf722e17431 100644 --- a/lib/analyzerinfo.cpp +++ b/lib/analyzerinfo.cpp @@ -24,7 +24,6 @@ #include "utils.h" #include -#include #include #include #include @@ -80,9 +79,11 @@ void AnalyzerInformation::writeFilesTxt(const std::string &buildDir, const std:: const std::string::size_type dotA = info.afile.rfind(".a"); if (dotA != std::string::npos) { const std::string base = info.afile.substr(0, dotA); - const unsigned int n = std::strtoul(info.afile.c_str() + dotA + 2, nullptr, 10); - unsigned int &count = fileCount[base]; - count = std::max(count, n); + unsigned int n = 0; + if (strToInt(info.afile.substr(dotA + 2), n)) { + unsigned int &count = fileCount[base]; + count = std::max(count, n); + } } } }