From b122db670b2b3d68f0ba199a1e25bdb1d8992241 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 13 Aug 2019 20:59:58 +0200 Subject: 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 --- stoc/source/typeconv/convert.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stoc') 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(rAny) ); - nRet = (fVal > SAL_MAX_INT64 ? static_cast(static_cast(fVal)) : static_cast(fVal)); if (fVal >= min && fVal <= max) { + nRet = (fVal >= 0.0 ? static_cast(static_cast(fVal)) : static_cast(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(rAny) ); - nRet = (fVal > SAL_MAX_INT64 ? static_cast(static_cast(fVal)) : static_cast(fVal)); if (fVal >= min && fVal <= max) { + nRet = (fVal >= 0.0 ? static_cast(static_cast(fVal)) : static_cast(fVal)); return nRet; } throw CannotConvertException( -- cgit