Skip to content

Commit 7f41039

Browse files
authored
fixed #13656 - fixed stack-use-after-scope in GUI (danmar#7330)
1 parent 80047b5 commit 7f41039

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

gui/checkthread.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <list>
3838
#include <set>
3939
#include <string>
40+
#include <utility>
4041
#include <vector>
4142

4243
#include <QByteArray>
@@ -110,11 +111,11 @@ CheckThread::CheckThread(ThreadResult &result) :
110111
mResult(result)
111112
{}
112113

113-
void CheckThread::setSettings(const Settings &settings, Suppressions& supprs)
114+
void CheckThread::setSettings(const Settings &settings, std::shared_ptr<Suppressions> supprs)
114115
{
115116
mFiles.clear();
116117
mSettings = settings; // this is a copy
117-
mSuppressions = &supprs;
118+
mSuppressions = std::move(supprs);
118119
}
119120

120121
void CheckThread::analyseWholeProgram(const QStringList &files, const std::string& ctuInfo)

gui/checkthread.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <atomic>
2727
#include <cstdint>
28+
#include <memory>
2829
#include <string>
2930
#include <vector>
3031

@@ -55,7 +56,7 @@ class CheckThread : public QThread {
5556
* @param settings settings for cppcheck
5657
* @param supprs suppressions for cppcheck
5758
*/
58-
void setSettings(const Settings &settings, Suppressions& supprs);
59+
void setSettings(const Settings &settings, std::shared_ptr<Suppressions> supprs);
5960

6061
/**
6162
* @brief Run whole program analysis
@@ -132,7 +133,7 @@ class CheckThread : public QThread {
132133
ThreadResult &mResult;
133134

134135
Settings mSettings;
135-
Suppressions* mSuppressions{};
136+
std::shared_ptr<Suppressions> mSuppressions;
136137

137138
private:
138139
void runAddonsAndTools(const Settings& settings, const FileSettings *fileSettings, const QString &fileName);

gui/mainwindow.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include <algorithm>
5757
#include <iterator>
5858
#include <list>
59+
#include <memory>
5960
#include <set>
6061
#include <string>
6162
#include <unordered_set>
@@ -542,8 +543,8 @@ void MainWindow::saveSettings() const
542543
void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, const bool checkConfiguration)
543544
{
544545
Settings checkSettings;
545-
Suppressions supprs;
546-
if (!getCppcheckSettings(checkSettings, supprs))
546+
auto supprs = std::make_shared<Suppressions>();
547+
if (!getCppcheckSettings(checkSettings, *supprs))
547548
return;
548549

549550
clearResults();
@@ -613,8 +614,8 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
613614
return;
614615

615616
Settings checkSettings;
616-
Suppressions supprs;
617-
if (!getCppcheckSettings(checkSettings, supprs))
617+
auto supprs = std::make_shared<Suppressions>();
618+
if (!getCppcheckSettings(checkSettings, *supprs))
618619
return;
619620

620621
clearResults();
@@ -1348,8 +1349,8 @@ void MainWindow::reAnalyzeSelected(const QStringList& files)
13481349
}
13491350

13501351
Settings checkSettings;
1351-
Suppressions supprs;
1352-
if (!getCppcheckSettings(checkSettings, supprs))
1352+
auto supprs = std::make_shared<Suppressions>();
1353+
if (!getCppcheckSettings(checkSettings, *supprs))
13531354
return;
13541355

13551356
// Clear details, statistics and progress
@@ -1383,8 +1384,8 @@ void MainWindow::reAnalyze(bool all)
13831384
return;
13841385

13851386
Settings checkSettings;
1386-
Suppressions supprs;
1387-
if (!getCppcheckSettings(checkSettings, supprs))
1387+
auto supprs = std::make_shared<Suppressions>();
1388+
if (!getCppcheckSettings(checkSettings, *supprs))
13881389
return;
13891390

13901391
// Clear details, statistics and progress

gui/threadhandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void ThreadHandler::setCheckFiles(const QStringList& files)
8383
}
8484
}
8585

86-
void ThreadHandler::check(const Settings &settings, Suppressions& supprs)
86+
void ThreadHandler::check(const Settings &settings, const std::shared_ptr<Suppressions>& supprs)
8787
{
8888
if (mResults.getFileCount() == 0 || mRunningThreadCount > 0 || settings.jobs == 0) {
8989
qDebug() << "Can't start checking if there's no files to check or if check is in progress.";

gui/threadhandler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "suppressions.h"
2424
#include "threadresult.h"
2525

26+
#include <memory>
2627
#include <set>
2728
#include <string>
2829

@@ -117,7 +118,7 @@ class ThreadHandler : public QObject {
117118
* @param settings Settings for checking
118119
* @param supprs Suppressions for checking
119120
*/
120-
void check(const Settings &settings, Suppressions& supprs);
121+
void check(const Settings &settings, const std::shared_ptr<Suppressions>& supprs);
121122

122123
/**
123124
* @brief Set files to check

0 commit comments

Comments
 (0)