aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-20 21:28:17 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-04-20 12:59:06 -0700
commit4aebcdc021391fcbdee089b5e14c11ebab517885 (patch)
treef10b2cf8eea67e215dae8dee779e68f1b8578034
parentd81df0dd198221ddec4571874507264ace8e21f3 (diff)
downloadsubsurface-4aebcdc021391fcbdee089b5e14c11ebab517885.tar.gz
core: return -1 from explicit_first_cylinder() if dive has no cylinders
Arguably, returning 0 for a dive with no cylinders is wrong, since the 0 is a valid cylinder id, however that cylinder doesn't exist. Instead, return -1. All callers of explicit_first_cylinder() return early anyway for dives with no cylinders. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/dive.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/dive.c b/core/dive.c
index 1658d3bdd..89e090165 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -961,10 +961,13 @@ static int same_rounded_pressure(pressure_t a, pressure_t b)
* tell us what the first gas is with a gas change event in the first sample.
* Sneakily we'll use a return value of 0 (or FALSE) when there is no explicit
* first cylinder - in which case cylinder 0 is indeed the first cylinder.
- * We likewise return 0 if the event concerns a cylinder that doesn't exist. */
+ * We likewise return 0 if the event concerns a cylinder that doesn't exist.
+ * If the dive has no cylinders, -1 is returned. */
int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc)
{
int res = 0;
+ if (!dive->cylinders.nr)
+ return -1;
if (dc) {
const struct event *ev = get_next_event(dc->events, "gaschange");
if (ev && ((dc->sample && ev->time.seconds == dc->sample[0].time.seconds) || ev->time.seconds <= 1))