diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-08-14 13:47:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-08-14 21:53:21 +0200 |
commit | b34472226495b35707d7df3c71bb8dbc3d11d6b8 (patch) | |
tree | 46c2f258dc1f506e42d23489e1cd1e7928647c85 /basic/source/sbx/sbxlng.cxx | |
parent | 866b4a41d50e11306e890f3033fe1fed9b69b709 (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/sbxlng.cxx')
-rw-r--r-- | basic/source/sbx/sbxlng.cxx | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/basic/source/sbx/sbxlng.cxx b/basic/source/sbx/sbxlng.cxx index cc832e8ed054..3a2a860dfdca 100644 --- a/basic/source/sbx/sbxlng.cxx +++ b/basic/source/sbx/sbxlng.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> @@ -57,11 +60,11 @@ start: nRes = static_cast<sal_Int32>(p->nULong); break; case SbxSINGLE: - if( p->nSingle > SbxMAXLNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(p->nSingle), SbxMAXLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXLNG; } - else if( p->nSingle < SbxMINLNG ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(p->nSingle), SbxMINLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINLNG; } @@ -98,11 +101,11 @@ start: else dVal = p->nDouble; - if( dVal > SbxMAXLNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(dVal), SbxMAXLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXLNG; } - else if( dVal < SbxMINLNG ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(dVal), SbxMINLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINLNG; } @@ -121,11 +124,11 @@ start: SbxDataType t; if( ImpScan( *p->pOUString, d, t, nullptr, false ) != ERRCODE_NONE ) nRes = 0; - else if( d > SbxMAXLNG ) + else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXLNG; } - else if( d < SbxMINLNG ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(d), SbxMINLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMINLNG; } |