Browse Source

Add tools/report-clang-tidy.sh

- Fix various clang-tidy warnings
- Fix use-after-free crash when deleting profiles
Aqua-sama 3 months ago
parent
commit
9e73d0dac0
Signed by: Aqua-sama <aqua@iserlohn-fortress.net> GPG Key ID: 5378B8349C1D5ADA

+ 30
- 0
.clang-tidy View File

@@ -0,0 +1,30 @@
1
+---
2
+Checks:          'clang-diagnostic-*,clang-analyzer-*,bugprone-*,cert-*,cppcoreguidelines-*,hicpp-*,misc-*,modernize-*,performance-*,portability-*,readability-*'
3
+WarningsAsErrors: ''
4
+HeaderFilterRegex: ''
5
+AnalyzeTemporaryDtors: false
6
+FormatStyle:     none
7
+User:            aqua
8
+CheckOptions:    
9
+  - key:             google-readability-braces-around-statements.ShortStatementLines
10
+    value:           '1'
11
+  - key:             google-readability-function-size.StatementThreshold
12
+    value:           '800'
13
+  - key:             google-readability-namespace-comments.ShortNamespaceLines
14
+    value:           '10'
15
+  - key:             google-readability-namespace-comments.SpacesBeforeComments
16
+    value:           '2'
17
+  - key:             modernize-loop-convert.MaxCopySize
18
+    value:           '16'
19
+  - key:             modernize-loop-convert.MinConfidence
20
+    value:           reasonable
21
+  - key:             modernize-loop-convert.NamingStyle
22
+    value:           CamelCase
23
+  - key:             modernize-pass-by-value.IncludeStyle
24
+    value:           llvm
25
+  - key:             modernize-replace-auto-ptr.IncludeStyle
26
+    value:           llvm
27
+  - key:             modernize-use-nullptr.NullMacros
28
+    value:           'NULL'
29
+...
30
+

+ 1
- 1
lib/about/aboutplugin.cpp View File

@@ -30,7 +30,7 @@ QTreeWidgetItem *createItem(const QString &key, const QJsonValue &json, QTreeWid
30 30
 
31 31
     case QJsonValue::Array:
32 32
         item->setText(1, QString());
33
-        for(const QJsonValue &v : json.toArray()) {
33
+        for(const auto &v : json.toArray()) {
34 34
             createItem(QString(), v, item);
35 35
         }
36 36
         break;

+ 1
- 1
lib/bookmarks/bookmarkswidget.cpp View File

@@ -135,7 +135,7 @@ void BookmarksWidget::addBookmark(const QString &title, const QString &url)
135 135
     model->appendBookmark(title, url, QModelIndex());
136 136
 }
137 137
 
138
-void BookmarksWidget::search(const QString &term, std::function<void(QStringList &)> callback) const
138
+void BookmarksWidget::search(const QString &term, const std::function<void(QStringList &)> &callback) const
139 139
 {
140 140
     QStringList ret = model->search(term);
141 141
     callback(ret);

+ 1
- 1
lib/bookmarks/bookmarkswidget.h View File

@@ -39,7 +39,7 @@ signals:
39 39
 public slots:
40 40
     void save();
41 41
     void addBookmark(const QString &title, const QString &url);
42
-    void search(const QString &term, std::function<void(QStringList &)> callback) const;
42
+    void search(const QString &term, const std::function<void(QStringList &)> &callback) const;
43 43
 
44 44
 private:
45 45
     Ui::BookmarksDialog *ui;

+ 1
- 1
lib/bookmarks/xbel.h View File

@@ -13,7 +13,7 @@ class QIODevice;
13 13
 class BookmarkItem;
14 14
 namespace Xbel
15 15
 {
16
-void read(QIODevice *device, BookmarkItem *model);
16
+void read(QIODevice *device, BookmarkItem *item);
17 17
 void write(QIODevice *device, const BookmarkItem *item);
18 18
 }
19 19
 

+ 2
- 2
lib/urlfilter/hostlist/hostlist.cpp View File

@@ -62,11 +62,11 @@ void HostList::parseLine(const QString& line)
62 62
         return;
63 63
 
64 64
     const QStringList parts = parsedLine.split(QLatin1Literal(" "));
65
-    const QString redirect = parts.at(0);
65
+    const QString &redirect = parts.at(0);
66 66
     const auto action = (redirect == QLatin1Literal("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect;
67 67
 
68 68
     for(int i = 1; i < parts.size(); i++) {
69
-        const QString domain = parts.at(i);
69
+        const QString &domain = parts.at(i);
70 70
         Rule r;
71 71
         r.action = action;
72 72
         r.domainHash = qHash(domain);

+ 3
- 2
lib/webprofile/webprofilemanager.cpp View File

@@ -27,8 +27,9 @@ WebProfileManager::~WebProfileManager()
27 27
                 if(!p.ptr->cachePath().isEmpty())
28 28
                     QDir(p.ptr->cachePath()).removeRecursively();
29 29
             }
30
+            const QString filename = p.settings->fileName();
30 31
             delete p.settings;
31
-            QFile::remove(p.settings->fileName());
32
+            QFile::remove(filename);
32 33
         } else if(p.settings != nullptr) {
33 34
 #ifdef QT_DEBUG
34 35
             qDebug("sync %s", qUtf8Printable(p.settings->fileName()));
@@ -132,7 +133,7 @@ void WebProfileManager::deleteProfile(const QString &id)
132 133
     }
133 134
 }
134 135
 
135
-void WebProfileManager::profileMenu(QMenu *menu, std::function<void(WebProfile *)> callback, WebProfile *current, bool checkable) const
136
+void WebProfileManager::profileMenu(QMenu *menu, const std::function<void(WebProfile *)> &callback, WebProfile *current, bool checkable) const
136 137
 {
137 138
     auto *group = new QActionGroup(menu);
138 139
     connect(menu, &QMenu::aboutToHide, group, &QActionGroup::deleteLater);

+ 1
- 1
lib/webprofile/webprofilemanager.h View File

@@ -39,7 +39,7 @@ public:
39 39
      */
40 40
     void deleteProfile(const QString &id);
41 41
 
42
-    void profileMenu(QMenu *menu, std::function<void(WebProfile *)> callback, WebProfile *current = nullptr, bool checkable = false) const;
42
+    void profileMenu(QMenu *menu, const std::function<void(WebProfile *)> &callback, WebProfile *current = nullptr, bool checkable = false) const;
43 43
 
44 44
     const QStringList idList() const
45 45
     {

+ 2
- 1
src/browser.cpp View File

@@ -216,11 +216,12 @@ void Browser::setup(QVector<QPluginLoader *> plugins)
216 216
     // bookmarks
217 217
     m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value()));
218 218
     connect(m_bookmarks.get(), &BookmarksWidget::showContextMenu, this, [this](const QUrl &url, const QPoint &pos) {
219
-        auto *menu = new QMenu(m_bookmarks.get());
220 219
         auto *subwindow = m_windows.last()->currentSubWindow();
221 220
         if(subwindow == nullptr)
222 221
             return;
223 222
 
223
+        auto *menu = new QMenu(m_bookmarks.get());
224
+
224 225
         menu->addAction(tr("Open link in current tab"), subwindow, [url, subwindow]() {
225 226
             subwindow->currentView()->load(url);
226 227
         });

+ 1
- 1
src/browser.h View File

@@ -90,7 +90,7 @@ private:
90 90
     std::unique_ptr<Configuration> m_config;
91 91
     std::shared_ptr<BookmarksWidget> m_bookmarks;
92 92
     std::unique_ptr<DownloadsWidget> m_downloads;
93
-    WebProfileManager *m_profileManager;
93
+    WebProfileManager *m_profileManager = nullptr;
94 94
     QVector<UrlFilter *> m_filters;
95 95
 
96 96
     QVector<MainWindow *> m_windows;

+ 3
- 3
src/builtins.cpp View File

@@ -36,9 +36,9 @@ int builtins::build()
36 36
 }
37 37
 
38 38
 int builtins::help(const char *cmd,
39
-    boost::program_options::options_description cmd_opts,
40
-    boost::program_options::options_description config_opts,
41
-    CommandHash_t pluginCommands, const QTranslator *translator)
39
+    const boost::program_options::options_description &cmd_opts,
40
+    const boost::program_options::options_description &config_opts,
41
+    const CommandHash_t &pluginCommands, const QTranslator *translator)
42 42
 {
43 43
     const auto version = QVersionNumber::fromString(QLatin1String(poi_Version)).toString().toStdString();
44 44
     std::cout << tr(translator, "smolbote ") << version << tr(translator, ": yet another no-frills browser\n");

+ 4
- 4
src/builtins.h View File

@@ -17,10 +17,10 @@ namespace builtins
17 17
 int version();
18 18
 int build();
19 19
 int help(const char *cmd,
20
-    boost::program_options::options_description cmd_opts,
21
-    boost::program_options::options_description config_opts,
22
-    CommandHash_t pluginCommands,
23
-         const QTranslator *translator);
20
+    const boost::program_options::options_description &cmd_opts,
21
+    const boost::program_options::options_description &config_opts,
22
+    const CommandHash_t &pluginCommands,
23
+    const QTranslator *translator);
24 24
 }
25 25
 
26 26
 #endif

+ 1
- 1
src/main.cpp View File

@@ -75,7 +75,7 @@ int main(int argc, char **argv)
75 75
 
76 76
     // Load plugins
77 77
     for(const QString &path : Util::files(config->value<QString>("plugins.path").value())) {
78
-        QPluginLoader *loader = new QPluginLoader(path);
78
+        auto *loader = new QPluginLoader(path);
79 79
         const bool loaded = loader->load();
80 80
 #ifdef QT_DEBUG
81 81
         qDebug("Loading plugin %s %s", qUtf8Printable(path), loaded ? "[ok]" : "[failed]");

+ 8
- 8
src/mainwindow/mainwindow.cpp View File

@@ -69,7 +69,7 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
69 69
         config->setShortcut(subwindowMenuAction, "subwindow.shortcuts.menu");
70 70
         connect(subwindowMenuAction, &QAction::triggered, this, [this]() {
71 71
             QMdiSubWindow *window = mdiArea->currentSubWindow();
72
-            if(window) {
72
+            if(window != nullptr) {
73 73
                 // show the menu at the subwindow position
74 74
                 // position has to be global, and mapped by the mdiArea (parentWidget() of the subwindow)
75 75
                 const auto position = mdiArea->mapToGlobal(window->pos());
@@ -114,20 +114,20 @@ MainWindow::MainWindow(const std::unique_ptr<Configuration> &config, QWidget *pa
114 114
 
115 115
     // address bar
116 116
     connect(addressBar, &AddressBar::search, this, [this](const QString &term) {
117
-        if(this->currentView) {
117
+        if(this->currentView != nullptr) {
118 118
             currentView->search(term);
119 119
             currentView->setFocus();
120 120
         }
121 121
     });
122 122
     connect(addressBar, &AddressBar::load, this, [this](const QUrl &url) {
123
-        if(this->currentView) {
123
+        if(this->currentView != nullptr) {
124 124
             currentView->load(url);
125 125
             currentView->setFocus();
126 126
         }
127 127
     });
128 128
 
129 129
     connect(addressBar, &AddressBar::giveFocus, this, [this]() {
130
-        if(this->currentView) {
130
+        if(this->currentView != nullptr) {
131 131
             currentView->setFocus();
132 132
         }
133 133
     });
@@ -244,13 +244,13 @@ SubWindow *MainWindow::createSubWindow(WebProfile *profile, bool openProfileNewt
244 244
 
245 245
 void MainWindow::setView(WebView *view)
246 246
 {
247
-    if(currentView) {
247
+    if(currentView != nullptr) {
248 248
         // disconnect old view
249
-        disconnect(currentView, 0, addressBar, 0);
249
+        disconnect(currentView, nullptr, addressBar, nullptr);
250 250
     }
251 251
     currentView = view;
252 252
 
253
-    if(view) {
253
+    if(view != nullptr) {
254 254
         connect(view, &WebView::urlChanged, addressBar, &AddressBar::setUrl);
255 255
         addressBar->setUrl(view->url());
256 256
 
@@ -277,7 +277,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
277 277
     }
278 278
 
279 279
     mdiArea->closeAllSubWindows();
280
-    if(mdiArea->currentSubWindow())
280
+    if(mdiArea->currentSubWindow() != nullptr)
281 281
         event->ignore();
282 282
     else
283 283
         event->accept();

+ 2
- 2
src/mainwindow/menubar.cpp View File

@@ -30,7 +30,7 @@
30 30
 #include <functional>
31 31
 #include <QVBoxLayout>
32 32
 
33
-inline void run_if(SubWindow *_subwindow, std::function<void(SubWindow*, int)> f)
33
+inline void run_if(SubWindow *_subwindow, const std::function<void(SubWindow*, int)> &f)
34 34
 {
35 35
     if(_subwindow != nullptr)
36 36
         f(_subwindow, _subwindow->currentTabIndex());
@@ -111,7 +111,7 @@ MenuBar::MenuBar(const Configuration *config, MainWindow *parent)
111 111
         const QString sessionPath = config->value<QString>("browser.session.path").value();
112 112
         auto *actionSaveSession = smolbote->addAction(tr("Save Session"), parent, [sessionPath]() {
113 113
             auto *sessionDialog = new SaveSessionDialog(nullptr);
114
-            if(sessionDialog->exec())
114
+            if(sessionDialog->exec() == QDialog::Accepted)
115 115
                 sessionDialog->save(sessionPath);
116 116
         });
117 117
         config->setShortcut(actionSaveSession, "mainwindow.shortcuts.saveSession");

+ 1
- 1
src/session/session.cpp View File

@@ -120,7 +120,7 @@ void Session::restoreView(WebView *view, const QJsonObject &data)
120 120
     Q_CHECK_PTR(profileManager);
121 121
 
122 122
     auto *profile = profileManager->profile(data["profile"].toString());
123
-    if(profile)
123
+    if(profile != nullptr)
124 124
         view->setProfile(profile);
125 125
 
126 126
     auto url = data.value("url");

+ 4
- 4
src/session/sessiondialog.cpp View File

@@ -35,11 +35,11 @@ SessionDialog::SessionDialog(QWidget *parent)
35 35
 
36 36
     connect(ui->listWidget, &QListWidget::currentItemChanged, this, [this](QListWidgetItem *currentItem, QListWidgetItem *previousItem) {
37 37
         auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(currentItem));
38
-        if(currentWidget)
38
+        if(currentWidget != nullptr)
39 39
             currentWidget->ui->delete_toolButton->show();
40 40
 
41 41
         auto *previousWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(previousItem));
42
-        if(previousWidget)
42
+        if(previousWidget != nullptr)
43 43
             previousWidget->ui->delete_toolButton->hide();
44 44
     });
45 45
 
@@ -53,7 +53,7 @@ SessionDialog::SessionDialog(QWidget *parent)
53 53
 
54 54
     accepted_connection = connect(this, &SessionDialog::accepted, this, [this, browser]() {
55 55
         auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
56
-        if(currentWidget)
56
+        if(currentWidget != nullptr)
57 57
             this->openSession(currentWidget->ui->label->text());
58 58
         else
59 59
             browser->createWindow();
@@ -76,7 +76,7 @@ std::optional<QJsonObject> SessionDialog::pickSession()
76 76
     }
77 77
 
78 78
     auto *currentWidget = qobject_cast<SessionForm *>(ui->listWidget->itemWidget(ui->listWidget->currentItem()));
79
-    if(currentWidget) {
79
+    if(currentWidget != nullptr) {
80 80
         QFile json(currentWidget->ui->label->text());
81 81
         if(json.open(QIODevice::ReadOnly | QIODevice::Text)) {
82 82
             auto doc = QJsonDocument::fromJson(json.readAll());

+ 0
- 0
src/webengine/webengineprofile.cpp View File


+ 0
- 0
src/webengine/webengineprofile.h View File


+ 0
- 4
tools/cppcheck.sh View File

@@ -1,4 +0,0 @@
1
-#!/bin/bash
2
-
3
-cppcheck --enable=all --verbose src/ lib/ plugins/ 2> report.txt
4
-

+ 16
- 0
tools/report-clang-tidy.sh View File

@@ -0,0 +1,16 @@
1
+#!/bin/bash
2
+
3
+cp build/compile_commands.json tidy/compile_commands.json
4
+
5
+# https://bugs.llvm.org/show_bug.cgi?id=37315
6
+sed -i 's/-pipe//g' tidy/compile_commands.json
7
+# do not scan system headers (replace -I with -isystem)
8
+sed -i 's/\-I\/usr\/include/\-isystem\/usr\/include/g' tidy/compile_commands.json
9
+
10
+for folder in $(find src lib -type d)
11
+do
12
+    if [[ $folder != *'test' ]]; then
13
+        clang-tidy -p tidy $folder/*.cpp $folder/*.h > reports/clangtidy-$(basename $folder).txt
14
+    fi
15
+done
16
+

+ 4
- 0
tools/report-cppcheck.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/bash
2
+
3
+cppcheck --enable=all --project=tidy/compile_commands.json 2> report.txt
4
+

Loading…
Cancel
Save