summaryrefslogtreecommitdiff
path: root/basic/source/sbx/sbxuint.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-08-14 13:47:17 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-08-14 21:53:21 +0200
commitb34472226495b35707d7df3c71bb8dbc3d11d6b8 (patch)
tree46c2f258dc1f506e42d23489e1cd1e7928647c85 /basic/source/sbx/sbxuint.cxx
parent866b4a41d50e11306e890f3033fe1fed9b69b709 (diff)
Fix Clang 10 -Werror,-Wimplicit-int-float-conversion
> basic/source/sbx/sbxint.cxx:342:13: error: implicit conversion from 'sal_Int64' (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion] > if( d > SAL_MAX_INT64 ) > ~ ^~~~~~~~~~~~~ > basic/source/sbx/sbxint.cxx:358:13: error: implicit conversion from 'sal_uInt64' (aka 'unsigned long') to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] > if( d > SAL_MAX_UINT64 ) > ~ ^~~~~~~~~~~~~~ > basic/source/sbx/sbxint.cxx:706:34: error: implicit conversion from 'sal_uInt64' (aka 'unsigned long') to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] > else if( d > SAL_MAX_UINT64 ) > ~ ^~~~~~~~~~~~~~ > basic/source/sbx/sbxlng.cxx:60:30: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion] > if( p->nSingle > SbxMAXLNG ) > ~ ^~~~~~~~~ > basic/source/sbx/sbxsng.cxx:280:21: error: implicit conversion from 'int' to 'float' changes value from 2147483647 to 2147483648 [-Werror,-Wimplicit-int-float-conversion] > if( n > SbxMAXLNG ) > ~ ^~~~~~~~~ > basic/source/sbx/sbxsng.cxx:297:21: error: implicit conversion from 'sal_uInt32' (aka 'unsigned int') to 'float' changes value from 4294967295 to 4294967296 [-Werror,-Wimplicit-int-float-conversion] > if( n > SbxMAXULNG ) > ~ ^~~~~~~~~~ > basic/source/sbx/sbxulng.cxx:66:30: error: implicit conversion from 'sal_uInt32' (aka 'unsigned int') to 'float' changes value from 4294967295 to 4294967296 [-Werror,-Wimplicit-int-float-conversion] > if( p->nSingle > SbxMAXULNG ) > ~ ^~~~~~~~~~ Consistently use o3tl::convertsToAtLeast/Most(o3tl::roundAway(...), ...) for all those conversion cases that check that a floating-point value falls into an integer range, even those that don't cause a warning. even those that don't con Change-Id: I008f615e9b4ad7533390aa1822cc932bf4a4b351 Reviewed-on: https://gerrit.libreoffice.org/77452 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'basic/source/sbx/sbxuint.cxx')
-rw-r--r--basic/source/sbx/sbxuint.cxx9
1 files changed, 6 insertions, 3 deletions
diff --git a/basic/source/sbx/sbxuint.cxx b/basic/source/sbx/sbxuint.cxx
index 59c421715a99..8a1aa458bc9c 100644
--- a/basic/source/sbx/sbxuint.cxx
+++ b/basic/source/sbx/sbxuint.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/float_int_conversion.hxx>
#include <vcl/errcode.hxx>
#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
@@ -105,7 +108,7 @@ start:
nRes = static_cast<sal_uInt16>(p->uInt64);
break;
case SbxSINGLE:
- if( p->nSingle > SbxMAXUINT )
+ if( !o3tl::convertsToAtMost(o3tl::roundAway(p->nSingle), SbxMAXUINT) )
{
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
}
@@ -131,7 +134,7 @@ start:
else
dVal = p->nDouble;
- if( dVal > SbxMAXUINT )
+ if( !o3tl::convertsToAtMost(o3tl::roundAway(dVal), SbxMAXUINT) )
{
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
}
@@ -154,7 +157,7 @@ start:
SbxDataType t;
if( ImpScan( *p->pOUString, d, t, nullptr, false ) != ERRCODE_NONE )
nRes = 0;
- else if( d > SbxMAXUINT )
+ else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXUINT) )
{
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXUINT;
}