summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-08-13 15:51:51 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-08-13 20:27:32 +0200
commit9c92c5e2a4bf15d673b5a8a2589b3109cb0603f7 (patch)
tree2da9090ee641fc12640310587582443702b8cd17 /sc/source
parentde8415ff5a730465258cd5f0ab7c0d989ba5518d (diff)
Fix Clang 10 -Werror,-Wimplicit-int-float-conversion
> sc/source/core/tool/interpr2.cxx:2889:26: error: implicit conversion from 'sal_uLong' (aka 'unsigned long') to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion] > if ( fVal <= sal_uLong(~0) ) > ~~ ^~~~~~~~~~~~~ > sc/source/core/tool/math.cxx:33:38: error: implicit conversion from 'sal_Int64' (aka 'long') to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion] > if (f < SAL_MIN_INT64 || f > SAL_MAX_INT64) > ~ ^~~~~~~~~~~~~ > sc/source/core/tool/rangeseq.cxx:55:38: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion] > if ( fInt >= LONG_MIN && fInt <= LONG_MAX ) > ~~ ^~~~~~~~ Change-Id: I01942423e43956a42bef11b9ccc2e7cb53bd1596 Reviewed-on: https://gerrit.libreoffice.org/77418 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/tool/interpr2.cxx3
-rw-r--r--sc/source/core/tool/math.cxx5
-rw-r--r--sc/source/core/tool/rangeseq.cxx3
3 files changed, 8 insertions, 3 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index ac5f174f4425..c01061533f00 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -21,6 +21,7 @@
#include <interpre.hxx>
#include <comphelper/string.hxx>
+#include <o3tl/float_int_conversion.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objsh.hxx>
@@ -2886,7 +2887,7 @@ void ScInterpreter::ScBase()
}
sal_Unicode* p = pBuf + nBuf - 1;
*p = 0;
- if ( fVal <= sal_uLong(~0) )
+ if ( o3tl::convertsToAtMost(fVal, sal_uLong(~0)) )
{
sal_uLong nVal = static_cast<sal_uLong>(fVal);
sal_uLong nBase = static_cast<sal_uLong>(fBase);
diff --git a/sc/source/core/tool/math.cxx b/sc/source/core/tool/math.cxx
index 73fbfcc29492..ffedee1514b5 100644
--- a/sc/source/core/tool/math.cxx
+++ b/sc/source/core/tool/math.cxx
@@ -12,6 +12,8 @@
#include <cerrno>
#include <cfenv>
+#include <o3tl/float_int_conversion.hxx>
+
namespace sc {
static double err_pow( const double& fVal1, const double& fVal2 )
@@ -30,7 +32,8 @@ double power( const double& fVal1, const double& fVal2 )
if (fVal1 < 0 && fVal2 != 0.0)
{
const double f = 1.0 / fVal2 + ((fVal2 < 0.0) ? -0.5 : 0.5);
- if (f < SAL_MIN_INT64 || f > SAL_MAX_INT64)
+ if (!(o3tl::convertsToAtLeast(f, SAL_MIN_INT64)
+ && o3tl::convertsToAtMost(f, SAL_MAX_INT64)))
{
// Casting to int would be undefined behaviour.
fPow = err_pow( fVal1, fVal2);
diff --git a/sc/source/core/tool/rangeseq.cxx b/sc/source/core/tool/rangeseq.cxx
index 86b614b0853a..909f5f3af9bb 100644
--- a/sc/source/core/tool/rangeseq.cxx
+++ b/sc/source/core/tool/rangeseq.cxx
@@ -19,6 +19,7 @@
#include <svl/zforlist.hxx>
#include <rtl/math.hxx>
+#include <o3tl/float_int_conversion.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/uno/Any.hxx>
@@ -52,7 +53,7 @@ static long lcl_DoubleToLong( double fVal )
{
double fInt = (fVal >= 0.0) ? ::rtl::math::approxFloor( fVal ) :
::rtl::math::approxCeil( fVal );
- if ( fInt >= LONG_MIN && fInt <= LONG_MAX )
+ if ( o3tl::convertsToAtLeast(fInt, LONG_MIN) && o3tl::convertsToAtMost(fInt, LONG_MAX) )
return static_cast<long>(fInt);
else
return 0; // out of range