Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #12837 - do not use empty filename in FileWithDetails in GUI (fixes cppcheck-gui crash) #6523

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions gui/threadresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ QString ThreadResult::getNextFile()
return mFiles.takeFirst();
}

FileSettings ThreadResult::getNextFileSettings()
void ThreadResult::getNextFileSettings(const FileSettings*& fs)
{
std::lock_guard<std::mutex> 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)
Expand All @@ -100,6 +100,7 @@ void ThreadResult::setProject(const ImportProject &prj)
std::lock_guard<std::mutex> locker(mutex);
mFiles.clear();
mFileSettings = prj.fileSettings;
mItNextFileSettings = mFileSettings.cbegin();
mProgress = 0;
mFilesChecked = 0;
mTotalFiles = prj.fileSettings.size();
Expand All @@ -116,6 +117,7 @@ void ThreadResult::clearFiles()
std::lock_guard<std::mutex> locker(mutex);
mFiles.clear();
mFileSettings.clear();
mItNextFileSettings = mFileSettings.cend();
mFilesChecked = 0;
mTotalFiles = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion gui/threadresult.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +137,7 @@ public slots:
QStringList mFiles;

std::list<FileSettings> mFileSettings;
std::list<FileSettings>::const_iterator mItNextFileSettings;

/**
* @brief Max progress
Expand Down
Loading