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>
This commit is contained in:
Dirk Hohndel 2019-10-27 16:08:50 -04:00
parent 1951371bbb
commit 130534aedf

View file

@ -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);
}