summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-11-22 21:07:57 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-11-22 16:22:57 -0800
commit13934b0f02a812cc5073ab21f2cbee754ecaee14 (patch)
treecd8d9a1b08deb283f55e7d885261a0b92aae0795 /dive.c
parent38bbed978a86d5b748ed61540632a25859cab7df (diff)
downloadsubsurface-13934b0f02a812cc5073ab21f2cbee754ecaee14.tar.gz
Check error code of get_cylider_idx_by_use()
If not cylinder with type DILUENT or OXYGEN is defined, this function returns -1 which should not be used as an index to an array. This patch adds code to check for this return value and exit gracefully. On line I marked with a comment. Someone more knowledgeable of that part of code than me should double check that return is here what we want. [Dirk Hohndel: fixed small oversight...] Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/dive.c b/dive.c
index 5a8da0119..b318c4be1 100644
--- a/dive.c
+++ b/dive.c
@@ -722,6 +722,8 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
if (dc->dctype == CCR) {
// Do the same for the O2 cylinder
int o2_cyl = get_cylinder_idx_by_use(dive, OXYGEN);
+ if (o2_cyl < 0)
+ return;
mean[o2_cyl] = dc->meandepth.mm;
duration[o2_cyl] = dc->duration.seconds;
}
@@ -775,6 +777,8 @@ static void fixup_pressure(struct dive *dive, struct sample *sample, enum cylind
pressure = sample->o2cylinderpressure.mbar;
index = get_cylinder_idx_by_use(dive, OXYGEN);
}
+ if (index < 0)
+ return;
if (!pressure)
return;
@@ -846,7 +850,7 @@ int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc)
if (ev && dc && dc->sample && ev->time.seconds == dc->sample[0].time.seconds)
return get_cylinder_index(dive, ev);
else if (dc->dctype == CCR)
- return get_cylinder_idx_by_use(dive, DILUENT);
+ return MAX(get_cylinder_idx_by_use(dive, DILUENT), 0);
else
return 0;
}