From 663ba147382b4eeba333a26534fbf77c44e8a035 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 13 Jun 2024 19:11:30 +0200 Subject: [PATCH] fixed #12837 - do not use empty filename in `FileWithDetails` in GUI (fixes `cppcheck-gui` crash) --- gui/checkthread.cpp | 13 +++++++------ gui/threadresult.cpp | 14 ++++++++------ gui/threadresult.h | 3 ++- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gui/checkthread.cpp b/gui/checkthread.cpp index 13e3c1dc2fe9..40ec77a8c86e 100644 --- a/gui/checkthread.cpp +++ b/gui/checkthread.cpp @@ -132,16 +132,17 @@ void CheckThread::run() file = mResult.getNextFile(); } - FileSettings fileSettings = mResult.getNextFileSettings(); - while (!fileSettings.filename().empty() && mState == Running) { - file = QString::fromStdString(fileSettings.filename()); + const FileSettings* fileSettings = nullptr; + mResult.getNextFileSettings(fileSettings); + while (fileSettings && mState == Running) { + file = QString::fromStdString(fileSettings->filename()); qDebug() << "Checking file" << file; - mCppcheck.check(fileSettings); - runAddonsAndTools(&fileSettings, QString::fromStdString(fileSettings.filename())); + mCppcheck.check(*fileSettings); + runAddonsAndTools(fileSettings, QString::fromStdString(fileSettings->filename())); emit fileChecked(file); if (mState == Running) - fileSettings = mResult.getNextFileSettings(); + mResult.getNextFileSettings(fileSettings); } if (mState == Running) diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index bbb373e95196..ad34b6ac7889 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -68,15 +68,15 @@ QString ThreadResult::getNextFile() return mFiles.takeFirst(); } -FileSettings ThreadResult::getNextFileSettings() +void ThreadResult::getNextFileSettings(const FileSettings*& fs) { std::lock_guard locker(mutex); - if (mFileSettings.empty()) { - return FileSettings(""); + fs = nullptr; + if (mItNextFileSettings == mFileSettings.cend()) { + return ; } - const FileSettings fs = mFileSettings.front(); - mFileSettings.pop_front(); - return fs; + fs = &(*mItNextFileSettings); + mItNextFileSettings++; } void ThreadResult::setFiles(const QStringList &files) @@ -100,6 +100,7 @@ void ThreadResult::setProject(const ImportProject &prj) std::lock_guard locker(mutex); mFiles.clear(); mFileSettings = prj.fileSettings; + mItNextFileSettings = mFileSettings.cbegin(); mProgress = 0; mFilesChecked = 0; mTotalFiles = prj.fileSettings.size(); @@ -116,6 +117,7 @@ void ThreadResult::clearFiles() std::lock_guard locker(mutex); mFiles.clear(); mFileSettings.clear(); + mItNextFileSettings = mFileSettings.cend(); mFilesChecked = 0; mTotalFiles = 0; } diff --git a/gui/threadresult.h b/gui/threadresult.h index faea466d44db..f9611eac2d4d 100644 --- a/gui/threadresult.h +++ b/gui/threadresult.h @@ -54,7 +54,7 @@ class ThreadResult : public QObject, public ErrorLogger { */ QString getNextFile(); - FileSettings getNextFileSettings(); + void getNextFileSettings(const FileSettings*& fs); /** * @brief Set list of files to check @@ -137,6 +137,7 @@ public slots: QStringList mFiles; std::list mFileSettings; + std::list::const_iterator mItNextFileSettings; /** * @brief Max progress