mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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>
This commit is contained in:
parent
99d1cecf06
commit
5a66ac7698
1 changed files with 8 additions and 9 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue