mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:13:23 +00:00
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>
This commit is contained in:
parent
d81df0dd19
commit
4aebcdc021
1 changed files with 4 additions and 1 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue