[PATCH 1/6] Add some assert guard around gas finding code
Anton Lundin
glance at acc.umu.se
Sat Dec 7 14:54:14 UTC 2013
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 <glance at acc.umu.se>
---
planner.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/planner.c b/planner.c
index 9e9ed47..a1954d0 100644
--- a/planner.c
+++ b/planner.c
@@ -4,6 +4,7 @@
*
* (c) Dirk Hohndel 2013
*/
+#include <assert.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
@@ -404,6 +405,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) {
@@ -412,6 +414,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
}
j++;
} while (j < MAX_CYLINDERS);
+ assert(gaschanges[i].gasidx != -1);
}
dp = dp->next;
}
--
1.8.3.2
More information about the subsurface
mailing list