diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-07-18 18:37:28 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-07-18 18:46:51 -0700 |
commit | 17bcd1bc6085013877888792754f52ce6b375aea (patch) | |
tree | bb4005fc606644336fd03d436fd1d5f7215e4928 /planner.c | |
parent | 359613210bf03d47fec5d19420f537aa5128f5cc (diff) | |
download | subsurface-17bcd1bc6085013877888792754f52ce6b375aea.tar.gz |
get_gas_at_time needs to always give us a valid gasv4.1.91
Before this function was changed it was really supposed to just change a
gas that was passed in in case there was an event that changed the mix -
but with the new name the caller will assume that they get a valid gasmix.
And promptly we had one caller that didn't initialize gas to be based on
the first cylinder before calling get_gas_at_time().
Instead of adding yet one more spot that knows about the oddity of the old
API I simply changed get_gas_at_time() to do what it name appears to imply
and fixed the other callers not to bother to initialize the gasmix.
Fixes #647
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r-- | planner.c | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -94,11 +94,13 @@ void set_display_transitions(bool display) plan_display_transitions = display; } +/* get the gas at a certain time during the dive */ void get_gas_at_time(struct dive *dive, struct divecomputer *dc, duration_t time, struct gasmix *gas) { - // we don't modify the values passed in if nothing is found - // so don't call with uninitialized gasmix ! + // we always start with the first gas, so that's our gas + // unless an event tells us otherwise struct event *event = dc->events; + *gas = dive->cylinder[0].gasmix; while (event && event->time.seconds <= time.seconds) { if (!strcmp(event->name, "gaschange")) { int cylinder_idx = get_cylinder_index(dive, event); @@ -153,8 +155,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap) if (!dc->samples) return tissue_tolerance; psample = sample = dc->sample; - /* we always start with gas 0 (unless an event tells us otherwise) */ - gas = dive->cylinder[0].gasmix; + for (i = 0; i < dc->samples; i++, sample++) { t1 = sample->time; get_gas_at_time(dive, dc, t0, &gas); @@ -551,7 +552,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool translate("gettextFromC", "gas")); } do { - struct gasmix gasmix, newgasmix; + struct gasmix gasmix, newgasmix = {}; const char *depth_unit; double depthvalue; int decimals; |