From 2938db287f95a772792420f887dec2d88413409b Mon Sep 17 00:00:00 2001
From: Pavel Karelin <hkarel@yandex.ru>
Date: Fri, 25 Nov 2022 22:02:00 +0300
Subject: [PATCH] Fixed segmentation fault when using CTRL+Left/Right on a
 panel with invalid path

FIXED: [ 462086 ]  Segmentation fault when using CTRL+Left/Right on a panel with invalid path
BUG: 462086

Discussion: https://invent.kde.org/utilities/krusader/-/merge_requests/117
---
 app/Panel/listpanel.cpp | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/app/Panel/listpanel.cpp b/app/Panel/listpanel.cpp
index dde22a257..be785a49f 100644
--- a/app/Panel/listpanel.cpp
+++ b/app/Panel/listpanel.cpp
@@ -913,26 +913,26 @@ void ListPanel::keyPressEvent(QKeyEvent *e)
             // user pressed CTRL+Right/Left - refresh other panel to the selected path if it's a
             // directory otherwise as this one
             if ((isLeft() && e->key() == Qt::Key_Right) || (!isLeft() && e->key() == Qt::Key_Left)) {
-                QUrl newPath;
-                KrViewItem *it = view->getCurrentKrViewItem();
-
-                if (it->name() == "..") {
-                    newPath = KIO::upUrl(virtualPath());
-                } else {
-                    FileItem *v = func->getFileItem(it);
-                    // If it's a directory different from ".."
-                    if (v && v->isDir() && v->getName() != "..") {
-                        newPath = v->getUrl();
+                if (KrViewItem *it = view->getCurrentKrViewItem()) {
+                    QUrl newPath;
+                    if (it->name() == "..") {
+                        newPath = KIO::upUrl(virtualPath());
                     } else {
-                        // If it's a supported compressed file
-                        if (v && KrArcHandler::arcSupported(v->getMime()))   {
-                            newPath = func->browsableArchivePath(v->getUrl().fileName());
+                        FileItem *v = func->getFileItem(it);
+                        // If it's a directory different from ".."
+                        if (v && v->isDir() && v->getName() != "..") {
+                            newPath = v->getUrl();
                         } else {
-                            newPath = virtualPath();
+                            // If it's a supported compressed file
+                            if (v && KrArcHandler::arcSupported(v->getMime()))   {
+                                newPath = func->browsableArchivePath(v->getUrl().fileName());
+                            } else {
+                                newPath = virtualPath();
+                            }
                         }
                     }
+                    otherPanel()->func->openUrl(newPath);
                 }
-                otherPanel()->func->openUrl(newPath);
             } else {
                 func->openUrl(otherPanel()->virtualPath());
             }
-- 
GitLab

