mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Prevent potential math overflow in new profile
Test for max_temp == min_temp to prevent math overflow when calculating temperature axis in new profile Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4159faa950
commit
2f822ec0dc
3 changed files with 46 additions and 1 deletions
2
dive.h
2
dive.h
|
@ -20,6 +20,8 @@
|
|||
(void) (&_max1 == &_max2); \
|
||||
_max1 > _max2 ? _max1 : _max2; })
|
||||
|
||||
#define IS_FP_SAME(_a,_b) (abs((_a) - (_b)) < 0.000001)
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <libxslt/transform.h>
|
||||
|
||||
|
|
42
dives/test9a.xml
Normal file
42
dives/test9a.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<dives>
|
||||
<program name='subsurface' version='1'></program>
|
||||
<dive number='9' date='2011-01-01' time='17:00:00' duration='30:00 min'>
|
||||
<depth max='30.0 m' mean='15.0 m' />
|
||||
<temperature air='27.0 C' water='26.0 C' />
|
||||
<location>9Ath test dive, with temperature in single sample</location>
|
||||
<notes>Test collapse of temperature axis due to max_temp == min_temp.</notes>
|
||||
<cylinder o2='33.0%' size='9.987 l' workpressure='206.843 bar' description='AL72' start='200.0 bar' end='100.0 bar' />
|
||||
<cylinder o2='50.0%' size='9.987 l' workpressure='206.843 bar' description='AL72' start='200.0 bar' end='100.0 bar' />
|
||||
<event time='15:00 min' name='gaschange' value='50' />
|
||||
<sample time='1:00 min' depth='5 m' />
|
||||
<sample time='2:00 min' depth='10 m' />
|
||||
<sample time='3:00 min' depth='15 m' />
|
||||
<sample time='4:00 min' depth='20 m' />
|
||||
<sample time='5:00 min' depth='25 m' />
|
||||
<sample time='6:00 min' depth='30 m' />
|
||||
<sample time='7:00 min' depth='30 m' />
|
||||
<sample time='8:00 min' depth='30 m' />
|
||||
<sample time='9:00 min' depth='30 m' />
|
||||
<sample time='10:00 min' depth='30 m' />
|
||||
<sample time='11:00 min' depth='30 m' />
|
||||
<sample time='12:00 min' depth='30 m' />
|
||||
<sample time='13:00 min' depth='30 m' />
|
||||
<sample time='14:00 min' temp='26.0 C' depth='10 m' />
|
||||
<sample time='15:00 min' depth='15 m' />
|
||||
<sample time='16:00 min' depth='5 m' />
|
||||
<sample time='17:00 min' depth='10 m' />
|
||||
<sample time='18:00 min' depth='10 m' />
|
||||
<sample time='19:00 min' depth='10 m' />
|
||||
<sample time='20:00 min' depth='10 m' />
|
||||
<sample time='21:00 min' depth='10 m' />
|
||||
<sample time='22:00 min' depth='5 m' />
|
||||
<sample time='23:00 min' depth='5 m' />
|
||||
<sample time='24:00 min' depth='5 m' />
|
||||
<sample time='25:00 min' depth='5 m' />
|
||||
<sample time='26:00 min' depth='5 m' />
|
||||
<sample time='27:00 min' depth='5 m' />
|
||||
<sample time='28:00 min' depth='5 m' />
|
||||
<sample time='29:00 min' depth='2.5 m' />
|
||||
<sample time='30:00 min' depth='0 m' />
|
||||
</dive>
|
||||
</dives>
|
|
@ -184,7 +184,8 @@ qreal DiveCartesianAxis::posAtValue(qreal value)
|
|||
double size = max - min;
|
||||
// unused for now:
|
||||
// double distanceFromOrigin = value - min;
|
||||
double percent = (value - min) / size;
|
||||
double percent = IS_FP_SAME(min,max) ? 0.0 : (value - min) / size;
|
||||
|
||||
|
||||
double realSize = orientation == LeftToRight || orientation == RightToLeft?
|
||||
m.x2() - m.x1() :
|
||||
|
|
Loading…
Add table
Reference in a new issue