From d7ca0c7253c00533e4c4bbaa022f49192c91f9ae Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 10 Nov 2022 12:33:11 +0100 Subject: [PATCH] planner: avoid out-of-bounds access When exiting the loop, stopidx is 0, which means that if there are no stoplevels, stoplevels[stopidx + 1] generates an out-of-bounds access. Instead, suppose a stop at 3m or 10ft. Suggested-by: Robert C. Helling Signed-off-by: Berthold Stoeger --- core/planner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/planner.c b/core/planner.c index a4c93ba77..d7aaf97b7 100644 --- a/core/planner.c +++ b/core/planner.c @@ -1087,7 +1087,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i * otherwise odd things can happen, such as CVA causing the final ascent to start *later* * if the ascent rate is slower, which is completely nonsensical. * Assume final ascent takes 20s, which is the time taken to ascend at 9m/min from 3m */ - ds->deco_time = clock - bottom_time - stoplevels[stopidx + 1] / last_ascend_rate + 20; + ds->deco_time = clock - bottom_time - (M_OR_FT(3,10) * ( prefs.last_stop ? 2 : 1)) / last_ascend_rate + 20; } while (!is_final_plan); decostoptable[decostopcounter].depth = 0;