mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-08 02:36:15 +00:00
Make fixup_divep robust against insane dive times
This fixes the case of the dive duration being zero, or being shorter than the assumed ascent/descent time. Reported-by: Lutz Vieweg <lvml@5t9.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
c26c370c2b
commit
1a05f34ae8
1 changed files with 11 additions and 4 deletions
15
dive.c
15
dive.c
|
@ -472,11 +472,18 @@ struct dive *fixup_dive(struct dive *dive)
|
||||||
cyl->sample_end.mbar = 0;
|
cyl->sample_end.mbar = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (end < 0)
|
if (end < 0) {
|
||||||
{
|
|
||||||
/* Assume an ascent/descent rate of 9 m/min */
|
/* Assume an ascent/descent rate of 9 m/min */
|
||||||
int asc_desc_time = dive->maxdepth.mm*60/9000;
|
int depth = dive->maxdepth.mm;
|
||||||
dive->meandepth.mm = dive->maxdepth.mm*(dive->duration.seconds-asc_desc_time)/dive->duration.seconds;
|
int asc_desc_time = depth*60/9000;
|
||||||
|
int duration = dive->duration.seconds;
|
||||||
|
|
||||||
|
/* Protect against insane dives - make mean be half of max */
|
||||||
|
if (duration <= asc_desc_time) {
|
||||||
|
duration = 2;
|
||||||
|
asc_desc_time = 1;
|
||||||
|
}
|
||||||
|
dive->meandepth.mm = depth*(duration-asc_desc_time)/duration;
|
||||||
return dive;
|
return dive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue