vcl/source/app/salvtables.cxx |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit a56981e9f1710ae44637fa6a31a37dc40c0c445a
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon Feb 7 19:27:04 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon Feb 7 23:45:31 2022 +0100

    float-cast-overflow
    
    ...after ea771e85b2302829394df545bb82c02bff2750c2 "Resolves: tdf#146997 use
    sal_Int64 instead of sal_Int32 for spinbutton values" changed the default 
value
    of pcr::ONumericControl::setMaxValue
    (extensions/source/propctrlr/standardcontrol.cxx) from int to sal_Int64 max.
    
    For example, UITest_calc_tests9 failed with
    
    > vcl/source/app/salvtables.cxx:5507:12: runtime error: 9.22337e+18 is 
outside the range of representable values of type 'long'
    >  #0 in SalInstanceSpinButton::fromField(double) const at 
vcl/source/app/salvtables.cxx:5507:12
    >  #1 in SalInstanceSpinButton::get_range(long&, long&) const at 
vcl/source/app/salvtables.cxx:5541:11
    >  #2 in weld::MetricSpinButton::update_width_chars() at 
vcl/source/window/builder.cxx:258:24
    >  #3 in weld::MetricSpinButton::set_range(long, long, FieldUnit) at 
include/vcl/weld.hxx:1991:9
    >  #4 in weld::MetricSpinButton::set_max(long, FieldUnit) at 
include/vcl/weld.hxx:2012:9
    >  #5 in 
pcr::ONumericControl::setMaxValue(com::sun::star::beans::Optional<double> 
const&) at extensions/source/propctrlr/standardcontrol.cxx:422:38
    
    because std::round(fValue * Power10(get_digits())) = 9223372036854775807 
(i.e.,
    2^63 - 1) cannot be represented as IEEE 754 double exactly and is 
represented as
    9223372036854775808, which was outside the range of sal_Int64, so treat 
that max
    limit value specially.  (The corresponding min limit value 
-9223372036854775808
    doesn't have that issue.)
    
    Change-Id: I9ff7a281278a0c66b0b0d49deb0846bcdb91a8fe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129639
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 778901f85d37..c320b43c8592 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -19,6 +19,7 @@
 
 #include <sal/config.h>
 
+#include <limits>
 #include <string_view>
 
 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
@@ -5504,7 +5505,10 @@ double SalInstanceSpinButton::toField(sal_Int64 nValue) 
const
 
 sal_Int64 SalInstanceSpinButton::fromField(double fValue) const
 {
-    return std::round(fValue * Power10(get_digits()));
+    auto const x = fValue * Power10(get_digits());
+    return x == double(std::numeric_limits<sal_Int64>::max())
+               ? std::numeric_limits<sal_Int64>::max()
+               : sal_Int64(std::round(x));
 }
 
 SalInstanceSpinButton::SalInstanceSpinButton(FormattedField* pButton, 
SalInstanceBuilder* pBuilder,

Reply via email to