summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Dario <ydario@apache.org>2012-07-18 20:32:47 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-05-27 10:23:07 +0100
commitba8485a9c87a5feca3c2673af532e73ecf517b69 (patch)
tree662e8864c7f2af416fc66ca7cf044ac4c1283027
parentec8e012e980c88c8f24a7de44e44d0319bae2801 (diff)
cast double to sal_Int64 can throw EXCEPTION_FLT_INVALID_OPERATION on Windows
cherry picked from commit eb34ba3c343807201c62a49a19d7616e1011c118) Conflicts: vcl/source/control/field.cxx Change-Id: I2fb03b1b03ea23259e9eca7305c3f86d80d79f21
-rw-r--r--vcl/source/control/field.cxx22
1 files changed, 15 insertions, 7 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 87043dd86f1a..38b800317ebe 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -677,14 +677,21 @@ sal_Int64 NumericFormatter::Normalize( sal_Int64 nValue ) const
sal_Int64 NumericFormatter::Denormalize( sal_Int64 nValue ) const
{
sal_Int64 nFactor = ImplPower10( GetDecimalDigits() );
+
+ if ((nValue < ( SAL_MIN_INT64 + nFactor )) ||
+ (nValue > ( SAL_MAX_INT64 - nFactor )))
+ {
+ return ( nValue / nFactor );
+ }
+
if( nValue < 0 )
{
- sal_Int64 nHalf = nValue < ( SAL_MIN_INT64 + nFactor )? 0 : nFactor/2;
+ sal_Int64 nHalf = nFactor/2;
return ((nValue-nHalf) / nFactor );
}
else
{
- sal_Int64 nHalf = nValue > ( SAL_MAX_INT64 - nFactor )? 0 : nFactor/2;
+ sal_Int64 nHalf = nFactor/2;
return ((nValue+nHalf) / nFactor );
}
}
@@ -1238,14 +1245,15 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, sa
{
double nDouble = nonValueDoubleToValueDouble( ConvertDoubleValue(
(double)nValue, mnBaseValue, nDecDigits, eInUnit, eOutUnit ) );
+ sal_Int64 nLong ;
// caution: precision loss in double cast
- sal_Int64 nLong = static_cast<sal_Int64>( nDouble );
-
- if ( nDouble >= (double)SAL_MAX_INT64 )
- nLong = SAL_MAX_INT64;
- else if ( nDouble <= (double)SAL_MIN_INT64 )
+ if ( nDouble <= (double)SAL_MIN_INT64 )
nLong = SAL_MIN_INT64;
+ else if ( nDouble >= (double)SAL_MAX_INT64 )
+ nLong = SAL_MAX_INT64;
+ else
+ nLong = static_cast<sal_Int64>( nDouble );
return nLong;
}