summaryrefslogtreecommitdiffstats
path: root/core/divelist.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-08-16 13:35:14 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-08-23 05:16:38 -0700
commitf5b11daffd6f240268ce78d72c64be43670988ea (patch)
tree99805cc176483e5f069a7920c11528e37cf0db8c /core/divelist.c
parentb6187f73aad09adb0b70af8d77f1af1a34a338f8 (diff)
downloadsubsurface-f5b11daffd6f240268ce78d72c64be43670988ea.tar.gz
Cleanup: return gasmix by value
Currently, get_gasmix_from_event() and get_gasmix() return pointers to either static or to (possibly changing) dive data. This seems like a dangerous practice and the returned data should be used immediately. Instead, return the gasmix by value. This is in preparation of const-ifying input parameters of a number of core functions, which will ultimately let the merge() function take const-arguments in preparation of undo of dive-merging. On common 64-bit systems gasmix (two "int"s) is the size of a pointer and can be returned in a register. On 32-bit systems a pointer to the struct to be filled out will be passed. Since get_gasmix() now returns a value, the first invocation is tested by a NULL-initialized "struct event *". Document this in a comment. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divelist.c')
-rw-r--r--core/divelist.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/core/divelist.c b/core/divelist.c
index b81e89d25..9c2484417 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -404,7 +404,7 @@ static int calculate_sac(struct dive *dive)
static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
{
struct divecomputer *dc = &dive->dc;
- struct gasmix *gasmix = NULL;
+ struct gasmix gasmix = { 0 };
int i;
struct event *ev = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
@@ -421,8 +421,8 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
for (j = t0; j < t1; j++) {
int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0);
- gasmix = get_gasmix(dive, dc, j, &ev, gasmix);
- add_segment(ds, depth_to_bar(depth, dive), gasmix, 1, sample->setpoint.mbar,
+ gasmix = get_gasmix(dive, dc, j, &ev, &gasmix);
+ add_segment(ds, depth_to_bar(depth, dive), &gasmix, 1, sample->setpoint.mbar,
get_current_divemode(&dive->dc, j, &evd, &current_divemode), dive->sac);
}
}