From 28943d2defe437872dafa4c0959177b54c3de4d0 Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Sat, 7 Dec 2013 23:54:14 +0100 Subject: Add some assert guard around gas finding code The code would have leaved gasidx undefined if it doesn't find a correct gas, so this asserts instead of using uninitialized variables as array index. Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- planner.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/planner.c b/planner.c index 0f21d1139..21878b6c5 100644 --- a/planner.c +++ b/planner.c @@ -4,6 +4,7 @@ * * (c) Dirk Hohndel 2013 */ +#include #include #include #include @@ -409,6 +410,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive i++; } gaschanges[i].depth = dp->depth; + gaschanges[i].gasidx = -1; do { if (dive->cylinder[j].gasmix.o2.permille == dp->o2 && dive->cylinder[j].gasmix.he.permille == dp->he) { @@ -417,6 +419,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive } j++; } while (j < MAX_CYLINDERS); + assert(gaschanges[i].gasidx != -1); } dp = dp->next; } -- cgit v1.2.3-70-g09d2