sc/source/core/inc/interpre.hxx | 2 ++ sc/source/core/tool/interpr2.cxx | 24 ++++++++++++------------ sc/source/core/tool/interpr4.cxx | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 12 deletions(-)
New commits: commit 030c77d3e048a5235691db316e614ce3335037fe Author: Eike Rathke <er...@redhat.com> AuthorDate: Mon Oct 16 13:51:28 2023 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Oct 17 08:55:42 2023 +0200 Resolves: tdf#157786 Use GetFloor32() for date days instead of GetInt32() Change-Id: I1d6242b516f4b23473151bb99cbdf1a057a15746 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158029 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit a5d263d3deca6315f9128bc785e9fb6cb2e697f1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158039 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 5897a6b6c757..64b9a8ae5b2c 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -427,6 +427,8 @@ private: sal_Int32 GetInt32(); /** if GetDoubleWithDefault() not within int32 limits sets nGlobalError and returns SAL_MAX_INT32 */ sal_Int32 GetInt32WithDefault( sal_Int32 nDefault ); + /** if GetDouble() not within int32 limits sets nGlobalError and returns SAL_MAX_INT32 */ + sal_Int32 GetFloor32(); /** if GetDouble() not within int16 limits sets nGlobalError and returns SAL_MAX_INT16 */ sal_Int16 GetInt16(); /** if GetDouble() not within uint32 limits sets nGlobalError and returns SAL_MAX_UINT32 */ diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 60bde22f534b..67ec57fef9ab 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -121,21 +121,21 @@ void ScInterpreter::ScGetActTime() void ScInterpreter::ScGetYear() { Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); PushDouble( static_cast<double>(aDate.GetYear()) ); } void ScInterpreter::ScGetMonth() { Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); PushDouble( static_cast<double>(aDate.GetMonth()) ); } void ScInterpreter::ScGetDay() { Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); PushDouble(static_cast<double>(aDate.GetDay())); } @@ -199,7 +199,7 @@ void ScInterpreter::ScGetDayOfWeek() nFlag = 1; Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); int nVal = static_cast<int>(aDate.GetDayOfWeek()); // MONDAY = 0 switch (nFlag) { @@ -240,7 +240,7 @@ void ScInterpreter::ScWeeknumOOo() sal_Int16 nFlag = GetInt16(); Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); PushInt( static_cast<int>(aDate.GetWeekOfYear( nFlag == 1 ? SUNDAY : MONDAY ))); } } @@ -254,7 +254,7 @@ void ScInterpreter::ScGetWeekOfYear() sal_Int16 nFlag = ( nParamCount == 1 ) ? 1 : GetInt16(); Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); sal_Int32 nMinimumNumberOfDaysInWeek; DayOfWeek eFirstDayOfWeek; @@ -296,7 +296,7 @@ void ScInterpreter::ScGetIsoWeekOfYear() if ( MustHaveParamCount( GetByte(), 1 ) ) { Date aDate = pFormatter->GetNullDate(); - aDate.AddDays( GetInt32()); + aDate.AddDays( GetFloor32()); PushInt( static_cast<int>(aDate.GetWeekOfYear()) ); } } @@ -571,7 +571,7 @@ void ScInterpreter::ScWorkday_MS() PushError( nErr ); else { - sal_Int32 nDays = GetInt32(); + sal_Int32 nDays = GetFloor32(); sal_uInt32 nDate = GetUInt32(); if (nGlobalError != FormulaError::NONE || (nDate > SAL_MAX_UINT32 - nNullDate)) { @@ -701,8 +701,8 @@ void ScInterpreter::ScGetDiffDate360() return; bool bFlag = nParamCount == 3 && GetBool(); - sal_Int32 nDate2 = GetInt32(); - sal_Int32 nDate1 = GetInt32(); + sal_Int32 nDate2 = GetFloor32(); + sal_Int32 nDate1 = GetFloor32(); if (nGlobalError != FormulaError::NONE) PushError( nGlobalError); else @@ -766,8 +766,8 @@ void ScInterpreter::ScGetDateDif() return; OUString aInterval = GetString().getString(); - sal_Int32 nDate2 = GetInt32(); - sal_Int32 nDate1 = GetInt32(); + sal_Int32 nDate2 = GetFloor32(); + sal_Int32 nDate1 = GetFloor32(); if (nGlobalError != FormulaError::NONE) { diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 97c3d06cdf49..45ae430f5025 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -2217,6 +2217,23 @@ sal_Int32 ScInterpreter::GetInt32WithDefault( sal_Int32 nDefault ) return double_to_int32(fVal); } +sal_Int32 ScInterpreter::GetFloor32() +{ + double fVal = GetDouble(); + if (!std::isfinite(fVal)) + { + SetError( GetDoubleErrorValue( fVal)); + return SAL_MAX_INT32; + } + fVal = rtl::math::approxFloor( fVal); + if (fVal < SAL_MIN_INT32 || SAL_MAX_INT32 < fVal) + { + SetError( FormulaError::IllegalArgument); + return SAL_MAX_INT32; + } + return static_cast<sal_Int32>(fVal); +} + sal_Int16 ScInterpreter::GetInt16() { double fVal = GetDouble();