From a08c6ac9e3c8ac162ce08b730fd6108e2f71213c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Fri, 29 Oct 2021 03:47:53 +0200 Subject: [PATCH] Prevent null pointer deference in methods for selection. This resolves the crash when exporting the Basket archive. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko --- src/archive.cpp | 3 ++- src/basket.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/archive.cpp b/src/archive.cpp index 3f3377c..aec789f 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -228,7 +228,8 @@ void Archive::saveBasketToArchive(Basket *basket, bool recursive, KTar *tar, TQS // Recursively save child baskets: BasketListViewItem *item = Global::bnpView->listViewItemForBasket(basket); - if (recursive && item->firstChild()) { + if (recursive && item && item->firstChild()) + { for (BasketListViewItem *child = (BasketListViewItem*) item->firstChild(); child; child = (BasketListViewItem*) child->nextSibling()) { saveBasketToArchive(child->basket(), recursive, tar, backgrounds, tempFolder, progress); } diff --git a/src/basket.cpp b/src/basket.cpp index 6e14c65..128c1cb 100644 --- a/src/basket.cpp +++ b/src/basket.cpp @@ -4469,12 +4469,20 @@ void Basket::noteUngroup() void Basket::unplugSelection(NoteSelection *selection) { + if (!selection) + { + return; + } for (NoteSelection *toUnplug = selection->firstStacked(); toUnplug; toUnplug = toUnplug->nextStacked()) unplugNote(toUnplug->note); } void Basket::insertSelection(NoteSelection *selection, Note *after) { + if (!selection) + { + return; + } for (NoteSelection *toUnplug = selection->firstStacked(); toUnplug; toUnplug = toUnplug->nextStacked()) { if (toUnplug->note->isGroup()) { Note *group = new Note(this); @@ -4496,6 +4504,10 @@ void Basket::insertSelection(NoteSelection *selection, Note *after) void Basket::selectSelection(NoteSelection *selection) { + if (!selection) + { + return; + } for (NoteSelection *toUnplug = selection->firstStacked(); toUnplug; toUnplug = toUnplug->nextStacked()) { if (toUnplug->note->isGroup()) selectSelection(toUnplug);