desktop: fix crash when right-clicking of trip headers

Commit e42fc1a1e9 introduced a
crash condition. Apparently the code attempts to test whether
the clicked-on item is a top-level dive. The "Collapse others"
menu item should not be shown in that case. It does this by
testing "d->divetrip". However, "d" might quite logically be
null if clicking on an unexpanded trip header.

Therefore, check explicitly for the trip header case (which
should show the menu item) and for good measure prevent
the nullpointer access (that should be caught by testing
for trip, but who knows).

Fixes #3301.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2021-08-12 08:26:08 +02:00 committed by bstoeger
parent f308a6b57b
commit 67769235e7

View file

@ -779,7 +779,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
popup.addAction(tr("Collapse all"), this, &QTreeView::collapseAll);
// verify if there`s a need for collapse others
if (expanded_nodes > 1 && d->divetrip)
if (expanded_nodes > 1 && (trip || (d && d->divetrip)))
collapseAction = popup.addAction(tr("Collapse others"), this, &QTreeView::collapseAll);