From 83e5df8a0172af575e22faad55c4a074128591cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Thu, 26 Oct 2023 18:55:13 +0100 Subject: [PATCH 1/5] Initialize variables Thanks to clang-tidy. --- src/main.cpp | 4 ++-- src/mainwindow.cpp | 2 +- src/qterminalutils.cpp | 2 +- src/termwidgetholder.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dee72544..9caead6c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,7 @@ QTerminalApp * QTerminalApp::m_instance = nullptr; void parse_args(int argc, char* argv[], QString& workdir, QStringList & shell_command, out bool& dropMode) { - int next_option; + int next_option = 0; dropMode = false; do{ next_option = getopt_long(argc, argv, short_options, long_options, nullptr); @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) QString workdir; QStringList shell_command; - bool dropMode; + bool dropMode = false; parse_args(argc, argv, workdir, shell_command, dropMode); Properties::Instance()->migrate_settings(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 18042ef2..44f9d27c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -914,7 +914,7 @@ bool MainWindow::hasMultipleSubterminals(QAction *) bool MainWindow::hasIndexedTab(QAction *action) { - bool ok; + bool ok = false; const int index = action->property("tab").toInt(&ok); Q_ASSERT(ok); static_cast(ok); diff --git a/src/qterminalutils.cpp b/src/qterminalutils.cpp index 62ce95e2..fcb671e2 100644 --- a/src/qterminalutils.cpp +++ b/src/qterminalutils.cpp @@ -29,7 +29,7 @@ QStringList parse_command(const QString& str) QStringList list; QRegularExpressionMatch match; int index = 0; - int nextIndex; + int nextIndex = 0; while((nextIndex = str.indexOf(separator, index, &match)) != -1) { if (nextIndex > index) diff --git a/src/termwidgetholder.cpp b/src/termwidgetholder.cpp index 95c556c4..5df3f3ab 100644 --- a/src/termwidgetholder.cpp +++ b/src/termwidgetholder.cpp @@ -75,7 +75,7 @@ void TermWidgetHolder::setInitialFocus() void TermWidgetHolder::loadSession() { - bool ok; + bool ok = false; QString name = QInputDialog::getItem(this, tr("Load Session"), tr("List of saved sessions:"), Properties::Instance()->sessions.keys(), From 05d1ddce93f1ca1c883c4f1a32063d77d93ea0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Thu, 26 Oct 2023 21:45:42 +0100 Subject: [PATCH 2/5] Initialize members in constructor Thanks to clang-tidy. --- src/bookmarkswidget.cpp | 2 +- src/tab-switcher.cpp | 8 ++++---- src/terminalconfig.cpp | 6 +++--- src/termwidget.cpp | 13 +++++++------ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/bookmarkswidget.cpp b/src/bookmarkswidget.cpp index 387d0a5e..78a485c4 100644 --- a/src/bookmarkswidget.cpp +++ b/src/bookmarkswidget.cpp @@ -323,10 +323,10 @@ bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, BookmarksWidget::BookmarksWidget(QWidget *parent) : QWidget(parent) + , m_model(new BookmarksModel(this)) { setupUi(this); - m_model = new BookmarksModel(this); treeView->setModel(m_model); treeView->header()->hide(); setFocusProxy(filterEdit); diff --git a/src/tab-switcher.cpp b/src/tab-switcher.cpp index 1a8f4710..cd7be312 100644 --- a/src/tab-switcher.cpp +++ b/src/tab-switcher.cpp @@ -89,15 +89,15 @@ class AppItemDelegate: public QStyledItemDelegate // ----------------------------------------------------------------------------------------------------------- -TabSwitcher::TabSwitcher(TabWidget* tabs): - QListView(tabs), - m_tabs(tabs) +TabSwitcher::TabSwitcher(TabWidget *tabs) + : QListView(tabs) + , m_timer(new QTimer(this)) + , m_tabs(tabs) { setWindowFlags(Qt::Widget | Qt::Popup | Qt::WindowStaysOnTopHint); setItemDelegate(new AppItemDelegate(frameWidth(), tabs)); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_timer = new QTimer(this); m_timer->setInterval(100); m_timer->setSingleShot(true); diff --git a/src/terminalconfig.cpp b/src/terminalconfig.cpp index 1497a298..85f78950 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -8,10 +8,10 @@ #include "properties.h" #include "termwidget.h" -TerminalConfig::TerminalConfig(const QString & wdir, const QStringList & shell) +TerminalConfig::TerminalConfig(const QString &wdir, const QStringList &shell) + : m_workingDirectory(wdir) + , m_shell(shell) { - m_workingDirectory = wdir; - m_shell = shell; } TerminalConfig::TerminalConfig() diff --git a/src/termwidget.cpp b/src/termwidget.cpp index 309b3847..935c4dd5 100644 --- a/src/termwidget.cpp +++ b/src/termwidget.cpp @@ -268,19 +268,20 @@ bool TermWidget::eventFilter(QObject * /*obj*/, QEvent * ev) return false; } -TermWidget::TermWidget(TerminalConfig &cfg, QWidget * parent) - : QWidget(parent), - DBusAddressable(QStringLiteral("/terminals")) +TermWidget::TermWidget(TerminalConfig &cfg, QWidget *parent) + : QWidget(parent) + , DBusAddressable(QStringLiteral("/terminals")) + , m_term(new TermWidgetImpl(cfg, this)) + , m_layout(new QVBoxLayout) + , m_border(palette().color(QPalette::Window)) { #ifdef HAVE_QDBUS registerAdapter(this); #endif - m_border = palette().color(QPalette::Window); - m_term = new TermWidgetImpl(cfg, this); + setFocusProxy(m_term); - m_layout = new QVBoxLayout; setLayout(m_layout); m_layout->addWidget(m_term); From 09000929b47e765bc598219a10852d516b2d9cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Thu, 26 Oct 2023 21:59:08 +0100 Subject: [PATCH 3/5] Remove duplicated include Thanks clang-tidy --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9caead6c..f436749d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,7 +26,6 @@ #include #ifdef HAVE_QDBUS #include - #include #include "processadaptor.h" #endif From 7438f4965058d96adc91c8d4f69694dd35b8f09e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Fri, 27 Oct 2023 12:16:59 +0100 Subject: [PATCH 4/5] Don't test before deleting a pointer It's fine to delete a null pointer. It has no effect. Assign nullptr after deleting make an access violation visible (crash). --- src/bookmarkswidget.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/bookmarkswidget.cpp b/src/bookmarkswidget.cpp index 78a485c4..e71fff9d 100644 --- a/src/bookmarkswidget.cpp +++ b/src/bookmarkswidget.cpp @@ -193,8 +193,7 @@ BookmarksModel::BookmarksModel(QObject *parent) void BookmarksModel::setup() { - if (m_root) - delete m_root; + delete m_root; m_root = new BookmarkRootItem(); m_root->addChild(new BookmarkFileGroupItem(m_root, Properties::Instance()->bookmarksFile)); beginResetModel(); @@ -203,8 +202,8 @@ void BookmarksModel::setup() BookmarksModel::~BookmarksModel() { - if (m_root) - delete m_root; + delete m_root; + m_root = nullptr; } int BookmarksModel::columnCount(const QModelIndex & /* parent */) const From 6982a2e52bdef9fcfa1a422d74b9a6b3e972c144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Fri, 27 Oct 2023 15:37:23 +0100 Subject: [PATCH 5/5] Use default to define a trivial constructor Thanks clang-tidy. --- src/bookmarkswidget.cpp | 4 +--- src/propertiesdialog.cpp | 5 +---- src/tab-switcher.cpp | 3 +-- src/terminalconfig.cpp | 4 +--- src/termwidgetholder.cpp | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/bookmarkswidget.cpp b/src/bookmarkswidget.cpp index e71fff9d..bab8f4db 100644 --- a/src/bookmarkswidget.cpp +++ b/src/bookmarkswidget.cpp @@ -341,9 +341,7 @@ BookmarksWidget::BookmarksWidget(QWidget *parent) }); } -BookmarksWidget::~BookmarksWidget() -{ -} +BookmarksWidget::~BookmarksWidget() = default; void BookmarksWidget::setup() { diff --git a/src/propertiesdialog.cpp b/src/propertiesdialog.cpp index 68565f0b..a64899dc 100644 --- a/src/propertiesdialog.cpp +++ b/src/propertiesdialog.cpp @@ -299,10 +299,7 @@ PropertiesDialog::PropertiesDialog(QWidget *parent) resize(s); } - -PropertiesDialog::~PropertiesDialog() -{ -} +PropertiesDialog::~PropertiesDialog() = default; void PropertiesDialog::accept() { diff --git a/src/tab-switcher.cpp b/src/tab-switcher.cpp index cd7be312..f91f02ab 100644 --- a/src/tab-switcher.cpp +++ b/src/tab-switcher.cpp @@ -104,8 +104,7 @@ TabSwitcher::TabSwitcher(TabWidget *tabs) connect(m_timer, &QTimer::timeout, this, &TabSwitcher::timer); } -TabSwitcher::~TabSwitcher() -{} +TabSwitcher::~TabSwitcher() = default; void TabSwitcher::showSwitcher() { diff --git a/src/terminalconfig.cpp b/src/terminalconfig.cpp index 85f78950..5e30ce88 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -14,9 +14,7 @@ TerminalConfig::TerminalConfig(const QString &wdir, const QStringList &shell) { } -TerminalConfig::TerminalConfig() -{ -} +TerminalConfig::TerminalConfig() = default; TerminalConfig::TerminalConfig(const TerminalConfig &cfg) : m_currentDirectory(cfg.m_currentDirectory), diff --git a/src/termwidgetholder.cpp b/src/termwidgetholder.cpp index 5df3f3ab..c0456d45 100644 --- a/src/termwidgetholder.cpp +++ b/src/termwidgetholder.cpp @@ -61,9 +61,7 @@ TermWidgetHolder::TermWidgetHolder(TerminalConfig &config, QWidget * parent) setLayout(lay); } -TermWidgetHolder::~TermWidgetHolder() -{ -} +TermWidgetHolder::~TermWidgetHolder() = default; void TermWidgetHolder::setInitialFocus() {