summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/locationinformation.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-27 16:08:50 -0400
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-28 05:44:33 -0700
commit130534aedfb7c9b48cceae5aca5a7c82f2444571 (patch)
tree3af3c9dd7bc1d09a378cf940ea377f23ad435b9e /desktop-widgets/locationinformation.cpp
parent1951371bbb1210b04a4133624734461286e4e44a (diff)
downloadsubsurface-130534aedfb7c9b48cceae5aca5a7c82f2444571.tar.gz
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 <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/locationinformation.cpp')
-rw-r--r--desktop-widgets/locationinformation.cpp14
1 files changed, 9 insertions, 5 deletions
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);
}