aboutsummaryrefslogtreecommitdiffstats
path: root/gaspressures.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 /gaspressures.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 'gaspressures.c')
-rw-r--r--gaspressures.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/gaspressures.c b/gaspressures.c
index 58e570423..4edcf7e35 100644
--- a/gaspressures.c
+++ b/gaspressures.c
@@ -271,6 +271,8 @@ static void fill_missing_tank_pressures(struct dive *dive, struct plot_info *pi,
if (o2_flag) {
// Find the cylinder index (cyl) and pressure
cyl = dive->oxygen_cylinder_index;
+ if (cyl < 0)
+ return; // Can we do this?!?
pressure = O2CYLINDER_PRESSURE(entry);
save_pressure = &(entry->o2cylinderpressure[SENSOR_PR]);
save_interpolated = &(entry->o2cylinderpressure[INTERPOLATED_PR]);
@@ -374,6 +376,8 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
if (o2_flag) { // if this is a diluent cylinder:
pressure = O2CYLINDER_PRESSURE(entry);
cylinderid = dive->oxygen_cylinder_index;
+ if (cylinderid < 0)
+ goto GIVE_UP;
} else {
pressure = SENSOR_PRESSURE(entry);
cylinderid = entry->cylinderindex;
@@ -424,6 +428,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
debug_print_pressures(pi);
#endif
+GIVE_UP:
for (i = 0; i < MAX_CYLINDERS; i++)
list_free(track_pr[i]);
}