mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Core: don't return invalid cylinders from explicit_first_cylinder()
For reasons which I don't yet understand, when plotting a dive whose first cylinder is not cylinder 0 and then plotting a dive with only one cylinder, it can happen that for the latter explicit_first_cylinder() returns an erroneous value. This is due to the way in which we copy the dive to be plotted to displayed_dive. For now, make sure that no invalid cylinder is returned to avoid crashes. This will have to be changed anyway, since this is very fundamentally not thread-safe and inefficient. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
763dbf256a
commit
62adc24d15
1 changed files with 6 additions and 4 deletions
10
core/dive.c
10
core/dive.c
|
@ -865,17 +865,19 @@ static int same_rounded_pressure(pressure_t a, pressure_t b)
|
||||||
/* Some dive computers (Cobalt) don't start the dive with cylinder 0 but explicitly
|
/* Some dive computers (Cobalt) don't start the dive with cylinder 0 but explicitly
|
||||||
* tell us what the first gas is with a gas change event in the first sample.
|
* 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
|
* 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 */
|
* 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. */
|
||||||
int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc)
|
int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc)
|
||||||
{
|
{
|
||||||
|
int res = 0;
|
||||||
if (dc) {
|
if (dc) {
|
||||||
const struct event *ev = get_next_event(dc->events, "gaschange");
|
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))
|
if (ev && ((dc->sample && ev->time.seconds == dc->sample[0].time.seconds) || ev->time.seconds <= 1))
|
||||||
return get_cylinder_index(dive, ev);
|
res = get_cylinder_index(dive, ev);
|
||||||
else if (dc->divemode == CCR)
|
else if (dc->divemode == CCR)
|
||||||
return MAX(get_cylinder_idx_by_use(dive, DILUENT), 0);
|
res = MAX(get_cylinder_idx_by_use(dive, DILUENT), 0);
|
||||||
}
|
}
|
||||||
return 0;
|
return res < dive->cylinders.nr ? res : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this gets called when the dive mode has changed (so OC vs. CC)
|
/* this gets called when the dive mode has changed (so OC vs. CC)
|
||||||
|
|
Loading…
Add table
Reference in a new issue