From fb09784060a10ef181e20d8e3adc3d7b1c55041e Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Thu, 17 May 2018 21:25:57 +0200 Subject: [PATCH] Don't compute SAC if total gas use is unknown If we breathe from a cylinder with invalid start or end pressures, we cannot reliably compute the total gas use and thus the SAC. So we should not pretend to do so. A better fix would compute the total SAC for only those segements that have valid start and end pressures. Reported-by: Stefan Fuchs Signed-off-by: Robert C. Helling --- core/divelist.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/divelist.c b/core/divelist.c index d5dc37271..6986c5a80 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -374,8 +374,16 @@ static double calculate_airuse(struct dive *dive) start = cyl->start.mbar ? cyl->start : cyl->sample_start; end = cyl->end.mbar ? cyl->end : cyl->sample_end; - if (!end.mbar || start.mbar <= end.mbar) - continue; + if (!end.mbar || start.mbar <= end.mbar) { + // If a cylinder is used but we do not have info on amout of gas used + // better not pretend we know the total gas use. + // Eventually, logic should be fixed to compute average depth and total time + // for those segments where cylinders with known pressure drop are breathed from. + if (is_cylinder_used(dive, i)) + return 0.0; + else + continue; + } airuse += gas_volume(cyl, start) - gas_volume(cyl, end); }