[Libreoffice-commits] core.git: sc/source
Stephan Bergmann
sbergman at redhat.com
Tue Jun 21 07:24:15 UTC 2016
sc/source/core/tool/interpr2.cxx | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
New commits:
commit 002697221215e009cdf20fd5c12b50350b8a2128
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Jun 21 09:23:42 2016 +0200
Avoid undefined behavior when converting from double to short
Change-Id: Idfae52f6807cec225a52d3d6c79f03fd9da965c1
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index c9a73d4..2eae22b 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -50,6 +50,7 @@
#include <com/sun/star/sheet/DataPilotFieldFilter.hpp>
+#include <limits>
#include <string.h>
#include <math.h>
@@ -191,7 +192,16 @@ void ScInterpreter::ScGetDayOfWeek()
{
short nFlag;
if (nParamCount == 2)
- nFlag = (short) ::rtl::math::approxFloor(GetDouble());
+ {
+ double x = rtl::math::approxFloor(GetDouble());
+ if (x > double(std::numeric_limits<short>::min()) - 1
+ && x < double(std::numeric_limits<short>::max()) + 1)
+ {
+ nFlag = static_cast<short>(x);
+ }
+ else
+ nFlag = -1; // cause error in switch below
+ }
else
nFlag = 1;
@@ -248,7 +258,24 @@ void ScInterpreter::ScGetWeekOfYear()
sal_uInt8 nParamCount = GetByte();
if ( MustHaveParamCount( nParamCount, 1, 2 ) )
{
- short nFlag = (nParamCount == 1) ? 1 : (short) ::rtl::math::approxFloor(GetDouble());
+ short nFlag;
+ if (nParamCount == 1)
+ {
+ nFlag = 1;
+ }
+ else
+ {
+ double x = rtl::math::approxFloor(GetDouble());
+ if (x > double(std::numeric_limits<short>::min()) - 1
+ && x < double(std::numeric_limits<short>::max()) + 1)
+ {
+ nFlag = static_cast<short>(x);
+ }
+ else
+ {
+ nFlag = -1; // cause error in switch below
+ }
+ }
Date aDate = *(pFormatter->GetNullDate());
aDate += (long)::rtl::math::approxFloor(GetDouble());
More information about the Libreoffice-commits
mailing list