diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-09-10 20:40:25 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-10 14:23:59 -0700 |
commit | 6e4a2538968d945d471489270136c4891b47b270 (patch) | |
tree | dbe442feff12bdb1414712e926eac593deb8a1d9 /core | |
parent | c75f53a7a802fd9745376b837f6c307ba82d5b7b (diff) | |
download | subsurface-6e4a2538968d945d471489270136c4891b47b270.tar.gz |
Profile: fix SAC calculation for air dives
Commit f5b11daffd6f240268ce78d72c64be43670988ea 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>
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.c | 9 | ||||
-rw-r--r-- | core/dive.h | 4 | ||||
-rw-r--r-- | core/divelist.c | 2 | ||||
-rw-r--r-- | core/plannernotes.c | 2 | ||||
-rw-r--r-- | core/profile.c | 6 |
5 files changed, 17 insertions, 6 deletions
diff --git a/core/dive.c b/core/dive.c index 53ca49bfd..a8814413a 100644 --- a/core/dive.c +++ b/core/dive.c @@ -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); } diff --git a/core/dive.h b/core/dive.h index 0cc3150ce..8b8b9fbf0 100644 --- a/core/dive.h +++ b/core/dive.h @@ -34,10 +34,14 @@ extern const char *cylinderuse_text[]; extern const char *divemode_text_ui[]; extern const char *divemode_text[]; +// o2 == 0 && he == 0 -> air +// o2 < 0 -> invalid struct gasmix { fraction_t o2; fraction_t he; }; +static const struct gasmix gasmix_invalid = { { -1 }, { -1 } }; +static const struct gasmix gasmix_air = { { 0 }, { 0 } }; typedef struct { diff --git a/core/divelist.c b/core/divelist.c index f643d14f6..1906d002a 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -405,7 +405,7 @@ static int calculate_sac(const struct dive *dive) static void add_dive_to_deco(struct deco_state *ds, struct dive *dive) { struct divecomputer *dc = &dive->dc; - struct gasmix gasmix = { 0 }; + struct gasmix gasmix = gasmix_air; int i; const struct event *ev = NULL, *evd = NULL; enum divemode_t current_divemode = UNDEF_COMP_TYPE; diff --git a/core/plannernotes.c b/core/plannernotes.c index 133f9a591..f768698ac 100644 --- a/core/plannernotes.c +++ b/core/plannernotes.c @@ -76,7 +76,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d struct membuffer icdbuf = { 0 }; const char *deco, *segmentsymbol; int lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1; - struct gasmix lastprintgasmix = {{ -1 }, { -1 }}; + struct gasmix lastprintgasmix = gasmix_invalid; struct divedatapoint *dp = diveplan->dp; bool plan_verbatim = prefs.verbatim_plan; bool plan_display_runtime = prefs.display_runtime; diff --git a/core/profile.c b/core/profile.c index 47fc97723..af7ebe271 100644 --- a/core/profile.c +++ b/core/profile.c @@ -780,7 +780,7 @@ static unsigned int matching_gases(struct dive *dive, struct gasmix gasmix) static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) { - struct gasmix gasmix = { 0 }; + struct gasmix gasmix = gasmix_invalid; const struct event *ev = NULL; unsigned int gases = 0; @@ -1021,7 +1021,7 @@ void calculate_deco_information(struct deco_state *ds, const struct deco_state * int last_ndl_tts_calc_time = 0, first_ceiling = 0, current_ceiling, last_ceiling = 0, final_tts = 0 , time_clear_ceiling = 0; if (decoMode() == VPMB) ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive); - struct gasmix gasmix = { 0 }; + struct gasmix gasmix = gasmix_invalid; const struct event *ev = NULL, *evd = NULL; enum divemode_t current_divemode = UNDEF_COMP_TYPE; @@ -1210,7 +1210,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer { int i; double amb_pressure; - struct gasmix gasmix = { 0 }; + struct gasmix gasmix = gasmix_invalid; const struct event *evg = NULL, *evd = NULL; enum divemode_t current_divemode = UNDEF_COMP_TYPE; |