Don't crash if get_divenr is called with NULL argument

We shouldn't be doing that, but still, let's not crash.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-07-03 21:18:40 -07:00
parent da911993f1
commit 947d7b77df

View file

@ -338,10 +338,12 @@ int get_divenr(struct dive *dive)
{
int i;
struct dive *d;
for_each_dive(i, d) {
if (d->id == dive->id) // don't compare pointers, we could be passing in a copy of the dive
return i;
}
// tempting as it may be, don't die when called with dive=NULL
if (dive)
for_each_dive(i, d) {
if (d->id == dive->id) // don't compare pointers, we could be passing in a copy of the dive
return i;
}
return -1;
}