diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-08-13 20:59:58 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-08-14 08:58:22 +0200 |
commit | b122db670b2b3d68f0ba199a1e25bdb1d8992241 (patch) | |
tree | ea21d406811fa539b1727fe2175bc6c8bd985e81 /stoc | |
parent | 9c92c5e2a4bf15d673b5a8a2589b3109cb0603f7 (diff) |
Reformulate TypeConverter_Impl::toHyper FLOAT/DOUBLE cases
...to avoid UB when fVal was cast to nRet *before* checking that fVal actually
fit into the bounds, and to avoid Clang 10
-Werror,-Wimplicit-int-float-conversion when comparing fVal against
SAL_MAX_INT64 ("implicit conversion from 'const sal_Int64' (aka 'const long') to
'double' changes value from 9223372036854775807 to 9223372036854775808")
Change-Id: I9e2f6c97309609d9ec2455d4ecf9c341d85c1680
Reviewed-on: https://gerrit.libreoffice.org/77430
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'stoc')
-rw-r--r-- | stoc/source/typeconv/convert.cxx | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx index 9ffef7287d6c..b74a3d1a5714 100644 --- a/stoc/source/typeconv/convert.cxx +++ b/stoc/source/typeconv/convert.cxx @@ -313,9 +313,9 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 case TypeClass_FLOAT: { double fVal = round( *o3tl::forceAccess<float>(rAny) ); - nRet = (fVal > SAL_MAX_INT64 ? static_cast<sal_Int64>(static_cast<sal_uInt64>(fVal)) : static_cast<sal_Int64>(fVal)); if (fVal >= min && fVal <= max) { + nRet = (fVal >= 0.0 ? static_cast<sal_Int64>(static_cast<sal_uInt64>(fVal)) : static_cast<sal_Int64>(fVal)); return nRet; } throw CannotConvertException( @@ -325,9 +325,9 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6 case TypeClass_DOUBLE: { double fVal = round( *o3tl::forceAccess<double>(rAny) ); - nRet = (fVal > SAL_MAX_INT64 ? static_cast<sal_Int64>(static_cast<sal_uInt64>(fVal)) : static_cast<sal_Int64>(fVal)); if (fVal >= min && fVal <= max) { + nRet = (fVal >= 0.0 ? static_cast<sal_Int64>(static_cast<sal_uInt64>(fVal)) : static_cast<sal_Int64>(fVal)); return nRet; } throw CannotConvertException( |