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 | |
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')
-rw-r--r-- | basic/source/sbx/sbxdbl.cxx | 19 | ||||
-rw-r--r-- | basic/source/sbx/sbxint.cxx | 23 | ||||
-rw-r--r-- | basic/source/sbx/sbxlng.cxx | 15 | ||||
-rw-r--r-- | basic/source/sbx/sbxsng.cxx | 21 | ||||
-rw-r--r-- | basic/source/sbx/sbxuint.cxx | 9 | ||||
-rw-r--r-- | basic/source/sbx/sbxulng.cxx | 9 |
6 files changed, 56 insertions, 40 deletions
diff --git a/basic/source/sbx/sbxdbl.cxx b/basic/source/sbx/sbxdbl.cxx index 823693c3a149..968dc837edb8 100644 --- a/basic/source/sbx/sbxdbl.cxx +++ b/basic/source/sbx/sbxdbl.cxx @@ -19,6 +19,7 @@ #include <config_features.h> +#include <o3tl/float_int_conversion.hxx> #include <vcl/errcode.hxx> #include <basic/sbx.hxx> #include "sbxconv.hxx" @@ -210,17 +211,17 @@ start: break; } case SbxBYREF | SbxCHAR: - if( n > SbxMAXCHAR ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXCHAR) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR; } - else if( n < SbxMINCHAR ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMINCHAR) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR; } *p->pChar = static_cast<sal_Unicode>(n); break; case SbxBYREF | SbxBYTE: - if( n > SbxMAXBYTE ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXBYTE) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE; } @@ -231,18 +232,18 @@ start: *p->pByte = static_cast<sal_uInt8>(n); break; case SbxBYREF | SbxINTEGER: case SbxBYREF | SbxBOOL: - if( n > SbxMAXINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT; } - else if( n < SbxMININT ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMININT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMININT; } *p->pInteger = static_cast<sal_Int16>(n); break; case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: - if( n > SbxMAXUINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXUINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT; } @@ -252,17 +253,17 @@ start: } *p->pUShort = static_cast<sal_uInt16>(n); break; case SbxBYREF | SbxLONG: - if( n > SbxMAXLNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXLNG; } - else if( n < SbxMINLNG ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMINLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINLNG; } *p->pLong = static_cast<sal_Int32>(n); break; case SbxBYREF | SbxULONG: - if( n > SbxMAXULNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXULNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXULNG; } diff --git a/basic/source/sbx/sbxint.cxx b/basic/source/sbx/sbxint.cxx index c29aba304935..78fc5756b0bf 100644 --- a/basic/source/sbx/sbxint.cxx +++ b/basic/source/sbx/sbxint.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> @@ -73,11 +76,11 @@ start: nRes = static_cast<sal_Int16>(p->nULong); break; case SbxSINGLE: - if( p->nSingle > SbxMAXINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(p->nSingle), SbxMAXINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT; } - else if( p->nSingle < SbxMININT ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(p->nSingle), SbxMININT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT; } @@ -134,11 +137,11 @@ start: else dVal = p->nDouble; - if( dVal > SbxMAXINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(dVal), SbxMAXINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT; } - else if( dVal < SbxMININT ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(dVal), SbxMININT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT; } @@ -157,11 +160,11 @@ start: SbxDataType t; if( ImpScan( *p->pOUString, d, t, nullptr, false ) != ERRCODE_NONE ) nRes = 0; - else if( d > SbxMAXINT ) + else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT; } - else if( d < SbxMININT ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(d), SbxMININT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMININT; } @@ -339,11 +342,11 @@ start: sal_Int64 ImpDoubleToSalInt64( double d ) { sal_Int64 nRes; - if( d > SAL_MAX_INT64 ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SAL_MAX_INT64) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_INT64; } - else if( d < SAL_MIN_INT64 ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(d), SAL_MIN_INT64) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MIN_INT64; } @@ -355,7 +358,7 @@ sal_Int64 ImpDoubleToSalInt64( double d ) sal_uInt64 ImpDoubleToSalUInt64( double d ) { sal_uInt64 nRes; - if( d > SAL_MAX_UINT64 ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SAL_MAX_UINT64) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_UINT64; } @@ -703,7 +706,7 @@ start: SbxDataType t; if( ImpScan( *p->pOUString, d, t, nullptr, false ) != ERRCODE_NONE ) nRes = 0; - else if( d > SAL_MAX_UINT64 ) + else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SAL_MAX_UINT64) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SAL_MAX_UINT64; } 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; } diff --git a/basic/source/sbx/sbxsng.cxx b/basic/source/sbx/sbxsng.cxx index b204d25827c4..2e74a672bd8a 100644 --- a/basic/source/sbx/sbxsng.cxx +++ b/basic/source/sbx/sbxsng.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> @@ -233,17 +236,17 @@ start: break; } case SbxBYREF | SbxCHAR: - if( n > SbxMAXCHAR ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXCHAR) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXCHAR; } - else if( n < SbxMINCHAR ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMINCHAR) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMINCHAR; } *p->pChar = static_cast<sal_Unicode>(n); break; case SbxBYREF | SbxBYTE: - if( n > SbxMAXBYTE ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXBYTE) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXBYTE; } @@ -254,18 +257,18 @@ start: *p->pByte = static_cast<sal_uInt8>(n); break; case SbxBYREF | SbxINTEGER: case SbxBYREF | SbxBOOL: - if( n > SbxMAXINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXINT; } - else if( n < SbxMININT ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMININT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMININT; } *p->pInteger = static_cast<sal_Int16>(n); break; case SbxBYREF | SbxERROR: case SbxBYREF | SbxUSHORT: - if( n > SbxMAXUINT ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXUINT) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); n = SbxMAXUINT; } @@ -277,11 +280,11 @@ start: case SbxBYREF | SbxLONG: { sal_Int32 i; - if( n > SbxMAXLNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); i = SbxMAXLNG; } - else if( n < SbxMINLNG ) + else if( !o3tl::convertsToAtLeast(o3tl::roundAway(n), SbxMINLNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); i = SbxMINLNG; } @@ -294,7 +297,7 @@ start: case SbxBYREF | SbxULONG: { sal_uInt32 i; - if( n > SbxMAXULNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(n), SbxMAXULNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); i = SbxMAXULNG; } 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; } diff --git a/basic/source/sbx/sbxulng.cxx b/basic/source/sbx/sbxulng.cxx index b78f0407af51..23699ed3c2b7 100644 --- a/basic/source/sbx/sbxulng.cxx +++ b/basic/source/sbx/sbxulng.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> @@ -63,7 +66,7 @@ start: case SbxULONG: nRes = p->nULong; break; case SbxSINGLE: - if( p->nSingle > SbxMAXULNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(p->nSingle), SbxMAXULNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXULNG; } @@ -98,7 +101,7 @@ start: else dVal = p->nDouble; - if( dVal > SbxMAXULNG ) + if( !o3tl::convertsToAtMost(o3tl::roundAway(dVal), SbxMAXULNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXULNG; } @@ -121,7 +124,7 @@ start: SbxDataType t; if( ImpScan( *p->pOUString, d, t, nullptr, false ) != ERRCODE_NONE ) nRes = 0; - else if( d > SbxMAXULNG ) + else if( !o3tl::convertsToAtMost(o3tl::roundAway(d), SbxMAXULNG) ) { SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXULNG; } |