From 86b8d796c8c0795aa5244479358e2f4b4533b1d9 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 22 Jun 2015 06:59:25 -0700 Subject: Prevent null pointer dereference Signed-off-by: Dirk Hohndel --- planner.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/planner.c b/planner.c index e5aa19efd..aee380b7e 100644 --- a/planner.c +++ b/planner.c @@ -595,7 +595,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool gaschange = true; if (plan_verbatim) { if (dp->depth != lastprintdepth) { - if (plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { + if (plan_display_transitions || dp->entered || !dp->next || (gaschange && nextdp && dp->next && dp->depth != nextdp->depth)) { if (dp->setpoint) snprintf(temp, sizeof(temp), translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"), decimals, depthvalue, depth_unit, @@ -616,7 +616,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool newdepth = dp->depth; lasttime = dp->time; } else { - if (dp->depth != nextdp->depth || gasmix_distance(&gasmix, &newgasmix) != 0 || dp->setpoint != nextdp->setpoint) { + if (nextdp && (dp->depth != nextdp->depth || gasmix_distance(&gasmix, &newgasmix) != 0 || dp->setpoint != nextdp->setpoint)) { if (dp->setpoint) snprintf(temp, sizeof(temp), translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s (SP = %.1fbar)"), decimals, depthvalue, depth_unit, @@ -637,7 +637,8 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool } } } else { - if ((dp->depth == lastdepth && dp->depth != nextdp->depth) || plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { + if ((dp->depth == lastdepth && nextdp && dp->depth != nextdp->depth) || + plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) { snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); len += snprintf(buffer + len, sizeof(buffer) - len, "%s", temp); if (plan_display_duration) { -- cgit v1.2.3-70-g09d2