aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2016-08-29 19:05:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-08-29 21:43:17 -0700
commit5a66ac7698afbe82e3d55549fd63590918d0a3d9 (patch)
treee1c0d594e9a4404b2fdc767438f5071744ca17ac /core
parent99d1cecf067daca5d7ed45effac659150e978504 (diff)
downloadsubsurface-5a66ac7698afbe82e3d55549fd63590918d0a3d9.tar.gz
Make sure DC_FIELD_TANK starts from a clean slate for each cylinder
We used to clear the 'dc_tank_t' for each dive, but then only clear the volume field in between each cylinder. That means that if the libdivecomputer back-end does not touch a field, it might contain the stale value from the previous tank information. I'm not sure this is actually much of an issue, since I'd expect back-ends do seem to initialize the fields fully (at least the EON Steel back-end does). But it's inconsistent. Also, the code was actually buggy because of the odd indentation: it would only ask for new tank information up to 'ntanks' tanks, but because of the final fixup that was done outside of the conditional, it would actually update the cylinder begin/end pressure data *beyond* 'ntanks', and just re-use the last libdivecomputer data for the rest of the cylinders. Again, in practice, that probably never really happened, but it is a real bug. The fixed-up code actually looks better too, imho, and is one line shorter because of the initialization now being done in one place rather than two. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/libdivecomputer.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 90c2c61cb..92e61b92c 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -99,7 +99,6 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
report_error("different number of gases (%d) and tanks (%d)", ngases, ntanks);
}
}
- dc_tank_t tank = { 0 };
#endif
for (i = 0; i < ngases; i++) {
@@ -136,8 +135,8 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
dive->cylinder[i].gasmix.he.permille = he;
#if DC_VERSION_CHECK(0, 5, 0) && defined(DC_GASMIX_UNKNOWN)
- tank.volume = 0.0;
if (i < ntanks) {
+ dc_tank_t tank = { 0 };
rc = dc_parser_get_field(parser, DC_FIELD_TANK, i, &tank);
if (rc == DC_STATUS_SUCCESS) {
cylinder_t *cyl = dive->cylinder + i;
@@ -191,14 +190,14 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
report_error("gasmix %d for tank %d doesn't match", tank.gasmix, i);
}
}
- }
- if (!IS_FP_SAME(tank.volume, 0.0))
- no_volume = false;
+ if (!IS_FP_SAME(tank.volume, 0.0))
+ no_volume = false;
- // this new API also gives us the beginning and end pressure for the tank
- if (!IS_FP_SAME(tank.beginpressure, 0.0) && !IS_FP_SAME(tank.endpressure, 0.0)) {
- dive->cylinder[i].start.mbar = tank.beginpressure * 1000;
- dive->cylinder[i].end.mbar = tank.endpressure * 1000;
+ // this new API also gives us the beginning and end pressure for the tank
+ if (!IS_FP_SAME(tank.beginpressure, 0.0) && !IS_FP_SAME(tank.endpressure, 0.0)) {
+ dive->cylinder[i].start.mbar = tank.beginpressure * 1000;
+ dive->cylinder[i].end.mbar = tank.endpressure * 1000;
+ }
}
#endif
if (no_volume) {