From ade8676d238d5a598dbe0770d73e6a604d99a2e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20J=2EV=2E=20Bertin?= Date: Sat, 9 Jun 2018 14:27:35 +0200 Subject: [PATCH] avoid nullptr dereference when no devices are found Differential revision: https://phabricator.kde.org/D13445 --- src/gui/mainwindow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 6eed849..d288d0b 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -758,6 +758,9 @@ void MainWindow::on_m_DeviceScanner_finished() void MainWindow::updateSeletedDeviceMenu() { QMenu* devicesMenu = static_cast(guiFactory()->container(QStringLiteral("selectedDevice"), this)); + if (!devicesMenu) + return; + devicesMenu->clear(); devicesMenu->setEnabled(!operationStack().previewDevices().isEmpty()); @@ -778,7 +781,7 @@ void MainWindow::onSelectedDeviceMenuTriggered(bool) QAction* action = qobject_cast(sender()); QMenu* devicesMenu = static_cast(guiFactory()->container(QStringLiteral("selectedDevice"), this)); - if (action == nullptr || action->parent() != devicesMenu) + if (action == nullptr || action->parent() != devicesMenu || !devicesMenu) return; const auto children = devicesMenu->findChildren(); @@ -791,6 +794,8 @@ void MainWindow::onSelectedDeviceMenuTriggered(bool) void MainWindow::on_m_ListDevices_selectionChanged(const QString& device_node) { QMenu* devicesMenu = static_cast(guiFactory()->container(QStringLiteral("selectedDevice"), this)); + if (!devicesMenu) + return; const auto children = devicesMenu->findChildren(); for (auto &entry : children)