tdf#170298 handle out of range value in EDATE function

otherwise the code will get stuck in an infinite loop

Change-Id: I5715df3e462f7cbde24bd6237fbd58d4c685272f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199525
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
(cherry picked from commit 08f940a22d)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/199688
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
This commit is contained in:
Noel Grandin
2026-02-19 12:17:53 +01:00
committed by Xisco Fauli
parent 66879873c9
commit 16c5aa0d23
+4 -2
View File
@@ -210,7 +210,6 @@ void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt
{
if( nDays < 0 )
throw lang::IllegalArgumentException();
sal_Int32 nTempDays;
sal_Int32 i = 0;
bool bCalc;
@@ -218,7 +217,10 @@ void DaysToDate( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt
do
{
nTempDays = nDays;
rYear = static_cast<sal_uInt16>((nTempDays / 365) - i);
sal_Int32 nTempYear = nTempDays / 365;
if (nTempYear > SAL_MAX_INT16)
throw lang::IllegalArgumentException("days value too large " + OUString::number(nDays), {}, 1);
rYear = static_cast<sal_uInt16>(nTempYear - i);
nTempDays -= (static_cast<sal_Int32>(rYear) -1) * 365;
nTempDays -= (( rYear -1) / 4) - (( rYear -1) / 100) + ((rYear -1) / 400);
bCalc = false;