Kaydet (Commit) 80c14439 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

INTEGRATION: CWS vcl85_SRC680 (1.22.136); FILE MERGED

2007/12/14 11:47:21 pl 1.22.136.1: #150733# take precautions for bad input values
üst bd45c56a
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: field.cxx,v $ * $RCSfile: field.cxx,v $
* *
* $Revision: 1.23 $ * $Revision: 1.24 $
* *
* last change: $Author: ihi $ $Date: 2008-01-14 16:21:03 $ * last change: $Author: rt $ $Date: 2008-01-29 16:16:54 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -38,28 +38,21 @@ ...@@ -38,28 +38,21 @@
#ifndef _BIGINT_HXX #ifndef _BIGINT_HXX
#define _TOOLS_BIGINT #define _TOOLS_BIGINT
#include <tools/bigint.hxx> #include "tools/bigint.hxx"
#endif #endif
#ifndef _DEBUG_HXX #include "tools/debug.hxx"
#include <tools/debug.hxx>
#endif
#ifndef _SV_RC_H #include "tools/rc.h"
#include <tools/rc.h> #include "tools/resary.hxx"
#endif #include "vcl/svids.hrc"
#ifndef _TOOLS_RESARY_HXX #include "vcl/field.hxx"
#include <tools/resary.hxx> #include "vcl/event.hxx"
#endif #include "vcl/svapp.hxx"
#ifndef _SV_SVIDS_HRC #include "vcl/svdata.hxx"
#include <vcl/svids.hrc> #include "vcl/unohelp.hxx"
#endif
#include <vcl/field.hxx>
#include <vcl/event.hxx>
#include <vcl/svapp.hxx>
#include <vcl/svdata.hxx>
#include <vcl/unohelp.hxx>
#include "rtl/math.hxx"
#ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX #ifndef _UNOTOOLS_LOCALEDATAWRAPPER_HXX
...@@ -1224,12 +1217,21 @@ static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, long& nDecDigits ) ...@@ -1224,12 +1217,21 @@ static FieldUnit ImplMap2FieldUnit( MapUnit meUnit, long& nDecDigits )
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
static double nonValueDoubleToValueDouble( double nValue )
{
return rtl::math::isFinite( nValue ) ? nValue : 0.0;
}
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, USHORT nDecDigits, sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, USHORT nDecDigits,
FieldUnit eInUnit, FieldUnit eOutUnit ) FieldUnit eInUnit, FieldUnit eOutUnit )
{ {
// caution: precision loss in double cast // caution: precision loss in double cast
return static_cast<sal_Int64>(ConvertDoubleValue( (double)nValue, mnBaseValue, nDecDigits, return static_cast<sal_Int64>(
eInUnit, eOutUnit ) ); // #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( (double)nValue, mnBaseValue, nDecDigits,
eInUnit, eOutUnit ) ) );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1237,7 +1239,11 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, US ...@@ -1237,7 +1239,11 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, sal_Int64 mnBaseValue, US
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits, sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits,
MapUnit eInUnit, FieldUnit eOutUnit ) MapUnit eInUnit, FieldUnit eOutUnit )
{ {
return static_cast<sal_Int64>(ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit )); return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1245,7 +1251,11 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits, ...@@ -1245,7 +1251,11 @@ sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits,
sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits, sal_Int64 MetricField::ConvertValue( sal_Int64 nValue, USHORT nDigits,
FieldUnit eInUnit, MapUnit eOutUnit ) FieldUnit eInUnit, MapUnit eOutUnit )
{ {
return static_cast<sal_Int64>(ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit )); return static_cast<sal_Int64>(
// #150733# cast double to sal_Int64 can throw a
// EXCEPTION_FLT_INVALID_OPERATION on Windows
nonValueDoubleToValueDouble(
ConvertDoubleValue( nValue, nDigits, eInUnit, eOutUnit ) ) );
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
...@@ -1255,7 +1265,7 @@ double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, US ...@@ -1255,7 +1265,7 @@ double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, US
{ {
if ( eInUnit != eOutUnit ) if ( eInUnit != eOutUnit )
{ {
sal_Int64 nMult, nDiv; sal_Int64 nMult = 1, nDiv = 1;
if ( eInUnit == FUNIT_PERCENT ) if ( eInUnit == FUNIT_PERCENT )
{ {
...@@ -1287,9 +1297,9 @@ double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, US ...@@ -1287,9 +1297,9 @@ double MetricField::ConvertDoubleValue( double nValue, sal_Int64 mnBaseValue, US
DBG_ASSERT( nDiv > 0, "illegal /" ); DBG_ASSERT( nDiv > 0, "illegal /" );
} }
if ( nMult != 1 ) if ( nMult != 1 && nMult > 0 )
nValue *= nMult; nValue *= nMult;
if ( nDiv != 1 ) if ( nDiv != 1 && nDiv > 0 )
{ {
nValue += ( nValue < 0 ) ? (-nDiv/2) : (nDiv/2); nValue += ( nValue < 0 ) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv; nValue /= nDiv;
...@@ -1342,9 +1352,12 @@ double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits, ...@@ -1342,9 +1352,12 @@ double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits,
sal_Int64 nDiv = aImplFactor[eFieldUnit][eOutUnit]; sal_Int64 nDiv = aImplFactor[eFieldUnit][eOutUnit];
sal_Int64 nMult = aImplFactor[eOutUnit][eFieldUnit]; sal_Int64 nMult = aImplFactor[eOutUnit][eFieldUnit];
if ( nMult != 1 ) DBG_ASSERT( nMult > 0, "illegal *" );
DBG_ASSERT( nDiv > 0, "illegal /" );
if ( nMult != 1 && nMult > 0)
nValue *= nMult; nValue *= nMult;
if ( nDiv != 1 ) if ( nDiv != 1 && nDiv > 0 )
{ {
nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2); nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv; nValue /= nDiv;
...@@ -1396,9 +1409,12 @@ double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits, ...@@ -1396,9 +1409,12 @@ double MetricField::ConvertDoubleValue( double nValue, USHORT nDigits,
sal_Int64 nDiv = aImplFactor[eInUnit][eFieldUnit]; sal_Int64 nDiv = aImplFactor[eInUnit][eFieldUnit];
sal_Int64 nMult = aImplFactor[eFieldUnit][eInUnit]; sal_Int64 nMult = aImplFactor[eFieldUnit][eInUnit];
if( nMult != 1 ) DBG_ASSERT( nMult > 0, "illegal *" );
DBG_ASSERT( nDiv > 0, "illegal /" );
if( nMult != 1 && nMult > 0 )
nValue *= nMult; nValue *= nMult;
if( nDiv != 1 ) if( nDiv != 1 && nDiv > 0 )
{ {
nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2); nValue += (nValue < 0) ? (-nDiv/2) : (nDiv/2);
nValue /= nDiv; nValue /= nDiv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment