diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2019-10-27 16:08:50 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-10-28 05:44:33 -0700 |
commit | 130534aedfb7c9b48cceae5aca5a7c82f2444571 (patch) | |
tree | 3af3c9dd7bc1d09a378cf940ea377f23ad435b9e | |
parent | 1951371bbb1210b04a4133624734461286e4e44a (diff) | |
download | subsurface-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>
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 14 |
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); } |