[Libreoffice-commits] core.git: Branch 'aoo/trunk' - chart2/source
Andre Fischer
af at apache.org
Fri Jan 24 04:08:05 PST 2014
chart2/source/view/axes/DateHelper.cxx | 17 ++++++++++++++---
chart2/source/view/axes/Tickmarks_Dates.cxx | 6 ++++++
2 files changed, 20 insertions(+), 3 deletions(-)
New commits:
commit 58a2b4a7f9f495eaf058e577ad3419f5a6c93d84
Author: Andre Fischer <af at apache.org>
Date: Fri Jan 24 10:36:16 2014 +0000
124069: Prevent infinite loop when looking too far into the future.
diff --git a/chart2/source/view/axes/DateHelper.cxx b/chart2/source/view/axes/DateHelper.cxx
index d007209..3545435 100644
--- a/chart2/source/view/axes/DateHelper.cxx
+++ b/chart2/source/view/axes/DateHelper.cxx
@@ -78,9 +78,20 @@ Date DateHelper::GetDateSomeMonthsAway( const Date& rD, long nMonthDistance )
Date DateHelper::GetDateSomeYearsAway( const Date& rD, long nYearDistance )
{
Date aRet(rD);
- aRet.SetYear( static_cast<sal_uInt16>(rD.GetYear()+nYearDistance) );
- while(!aRet.IsValid())
- aRet--;
+ const long nFutureYear (rD.GetYear()+nYearDistance);
+ aRet.SetYear(static_cast<sal_uInt16>(nFutureYear));
+ if ( ! aRet.IsValid())
+ {
+ // The Date class has the nasty property to store years modulo
+ // 10000. In order to handle (probably invalid) very large
+ // year values more gracefully than with an infinite loop we
+ // check that condition and return an invalid date.
+ if (nFutureYear < 10000)
+ {
+ while ( ! aRet.IsValid())
+ --aRet;
+ }
+ }
return aRet;
}
diff --git a/chart2/source/view/axes/Tickmarks_Dates.cxx b/chart2/source/view/axes/Tickmarks_Dates.cxx
index a6ec18f..749a7be 100644
--- a/chart2/source/view/axes/Tickmarks_Dates.cxx
+++ b/chart2/source/view/axes/Tickmarks_Dates.cxx
@@ -105,6 +105,7 @@ void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& r
break;
//find next major date
+ const Date aTmpDate (aDate);
switch( m_aIncrement.MajorTimeInterval.TimeUnit )
{
case DAY:
@@ -118,6 +119,8 @@ void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& r
aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MajorTimeInterval.Number );
break;
}
+ if ( ! aDate.IsValid() || aDate == aTmpDate)
+ break;
}
//create minor date tickinfos
@@ -136,6 +139,7 @@ void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& r
break;
//find next minor date
+ const Date aTmpDate (aDate);
switch( m_aIncrement.MinorTimeInterval.TimeUnit )
{
case DAY:
@@ -149,6 +153,8 @@ void DateTickFactory::getAllTicks( ::std::vector< ::std::vector< TickInfo > >& r
aDate = DateHelper::GetDateSomeMonthsAway( aDate, m_aIncrement.MinorTimeInterval.Number );
break;
}
+ if ( ! aDate.IsValid() || aDate == aTmpDate)
+ break;
}
}
More information about the Libreoffice-commits
mailing list