From 130534aedfb7c9b48cceae5aca5a7c82f2444571 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 27 Oct 2019 16:08:50 -0400 Subject: Cleanup: better handling of NULL dive in setCurrentDiveSite We test for d being NULL so that's clearly an option we worried about, yet we already called get_dive_site_for_dive(d) which dereferences d. Found by Coverity. Fixes CID 350118 Signed-off-by: Dirk Hohndel --- desktop-widgets/locationinformation.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 4f1241d82..b9146a178 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -567,14 +567,18 @@ void DiveLocationLineEdit::fixPopupPosition() void DiveLocationLineEdit::setCurrentDiveSite(struct dive *d) { - struct dive_site *ds = get_dive_site_for_dive(d); - currDs = ds; + location_t currentLocation; + if (d) { + currDs = get_dive_site_for_dive(d); + currentLocation = dive_get_gps_location(d); + } else { + currDs = nullptr; + currentLocation = location_t{0, 0}; + } if (!currDs) clear(); else - setText(ds->name); - - location_t currentLocation = d ? dive_get_gps_location(d) : location_t{0, 0}; + setText(currDs->name); proxy->setCurrentLocation(currentLocation); delegate.setCurrentLocation(currentLocation); } -- cgit v1.2.3-70-g09d2