Profile: fix SAC calculation for air dives

Commit f5b11daffd changed gasmix
arguments and return values to be passed by value instead of
using pointers.

Notably, get_gasmix() is fed a default-value and returns a
new value. In the old code, NULL was passed in in a first
loop iteration and non-NULL was always returned in the first
iteration. Thus, an equality comparison of passed-in an
returned gasmix would always fail in the first loop iteration.

The new code passed in air as default. Now if air was also
returned, then the matching gases were not calculated in
calculate_sac(). To revert to the old behavior, pass in
an invalid gasmix.

Moreover, give names to the invalid and air gasmixes.

Reported-by: tormento <turment@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-09-10 20:40:25 +02:00 committed by Dirk Hohndel
parent c75f53a7a8
commit 6e4a253896
6 changed files with 18 additions and 7 deletions

View file

@ -2205,8 +2205,15 @@ void cylinder_renumber(struct dive *dive, int mapping[])
dc_cylinder_renumber(dive, dc, mapping);
}
static bool gasmix_is_invalid(struct gasmix mix)
{
return mix.o2.permille < 0;
}
int same_gasmix(struct gasmix a, struct gasmix b)
{
if (gasmix_is_invalid(a) || gasmix_is_invalid(b))
return 0;
if (gasmix_is_air(a) && gasmix_is_air(b))
return 1;
return a.o2.permille == b.o2.permille && a.he.permille == b.he.permille;
@ -4314,6 +4321,6 @@ struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc,
struct gasmix get_gasmix_at_time(const struct dive *d, const struct divecomputer *dc, duration_t time)
{
const struct event *ev = NULL;
struct gasmix gasmix = { 0 };
struct gasmix gasmix = gasmix_air;
return get_gasmix(d, dc, time.seconds, &ev, gasmix);
}