From edecb0fcf904bb8d5901094b2e96079da644694d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Fri, 8 Nov 2013 21:40:59 +0900 Subject: Don't access invalid elements with depth = 0 This is a corner case in the planner that was exposed by the recent changes to the way the dive plan reflects the gases during the dive. Signed-off-by: Dirk Hohndel --- planner.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/planner.c b/planner.c index abefb6213..687da8273 100644 --- a/planner.c +++ b/planner.c @@ -616,7 +616,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, b for (stopidx = 0; stopidx < sizeof(decostoplevels) / sizeof(int); stopidx++) if (decostoplevels[stopidx] >= depth) break; - stopidx--; + if (stopidx > 0) + stopidx--; /* so now we know the first decostop level above us * NOTE, this could be the surface or a long list of potential stops -- cgit v1.2.3-70-g09d2