From 947d7b77df48cfa251a6f3a56b6b56d3bc33747f Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 3 Jul 2014 21:18:40 -0700 Subject: 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 --- divelist.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/divelist.c b/divelist.c index d1634a634..632b7703c 100644 --- a/divelist.c +++ b/divelist.c @@ -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; } -- cgit v1.2.3-70-g09d2