mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
9c5e037a61
commit
51345e4ad8
1 changed files with 3 additions and 2 deletions
5
dive.c
5
dive.c
|
@ -363,10 +363,11 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
|
||||||
if (ev && time >= ev->time.seconds) {
|
if (ev && time >= ev->time.seconds) {
|
||||||
int o2 = (ev->value & 0xFFFF) * 10;
|
int o2 = (ev->value & 0xFFFF) * 10;
|
||||||
int he = (ev->value >> 16) * 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");
|
ev = get_next_event(ev->next, "gaschange");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We ignore segments at the surface */
|
/* We ignore segments at the surface */
|
||||||
if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
|
if (depth > SURFACE_THRESHOLD || lastdepth > SURFACE_THRESHOLD) {
|
||||||
duration[idx] += time - lasttime;
|
duration[idx] += time - lasttime;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue