diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-11-20 07:44:45 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-20 07:44:45 -0800 |
commit | 51345e4ad828918a4e20b6aba40c3b0a137b1e73 (patch) | |
tree | dc4507aadf8ab3efc0e6f5a936fcd90223bd1610 | |
parent | 9c5e037a612808a9ad1d2c9f8e6ec7213d5d468b (diff) | |
download | subsurface-51345e4ad828918a4e20b6aba40c3b0a137b1e73.tar.gz |
Fix potential crash in the per tank sac calculation
In an inconsistant XML file (like our own dives/test20.xml) it is possible
that a gas change event refers to a non-existing gas. In that case
get_gasidx returns -1 - which we shouldn't use as index into the arrays.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -363,10 +363,11 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me if (ev && time >= ev->time.seconds) { int o2 = (ev->value & 0xFFFF) * 10; int he = (ev->value >> 16) * 10; - idx = get_gasidx(dive, o2, he); + int tank = get_gasidx(dive, o2, he); + if (tank >= 0) + idx = tank; // should never happen unless the input file is inconsistent ev = get_next_event(ev->next, "gaschange"); } - /* We ignore segments at the surface */ if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) { duration[idx] += time - lasttime; |