Author: af
Date: Fri Jan 24 10:36:16 2014
New Revision: 1560934
URL: http://svn.apache.org/r1560934
Log:
124069: Prevent infinite loop when looking too far into the future.
Modified:
openoffice/trunk/main/chart2/source/view/axes/DateHelper.cxx
openoffice/trunk/main/chart2/source/view/axes/Tickmarks_Dates.cxx
Modified: openoffice/trunk/main/chart2/source/view/axes/DateHelper.cxx
URL:
http://svn.apache.org/viewvc/openoffice/trunk/main/chart2/source/view/axes/DateHelper.cxx?rev=1560934&r1=1560933&r2=1560934&view=diff
==============================================================================
--- openoffice/trunk/main/chart2/source/view/axes/DateHelper.cxx (original)
+++ openoffice/trunk/main/chart2/source/view/axes/DateHelper.cxx Fri Jan 24
10:36:16 2014
@@ -78,9 +78,20 @@ Date DateHelper::GetDateSomeMonthsAway(
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;
}
Modified: openoffice/trunk/main/chart2/source/view/axes/Tickmarks_Dates.cxx
URL:
http://svn.apache.org/viewvc/openoffice/trunk/main/chart2/source/view/axes/Tickmarks_Dates.cxx?rev=1560934&r1=1560933&r2=1560934&view=diff
==============================================================================
--- openoffice/trunk/main/chart2/source/view/axes/Tickmarks_Dates.cxx (original)
+++ openoffice/trunk/main/chart2/source/view/axes/Tickmarks_Dates.cxx Fri Jan
24 10:36:16 2014
@@ -105,6 +105,7 @@ void DateTickFactory::getAllTicks( ::std
break;
//find next major date
+ const Date aTmpDate (aDate);
switch( m_aIncrement.MajorTimeInterval.TimeUnit )
{
case DAY:
@@ -118,6 +119,8 @@ void DateTickFactory::getAllTicks( ::std
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
break;
//find next minor date
+ const Date aTmpDate (aDate);
switch( m_aIncrement.MinorTimeInterval.TimeUnit )
{
case DAY:
@@ -149,6 +153,8 @@ void DateTickFactory::getAllTicks( ::std
aDate = DateHelper::GetDateSomeMonthsAway( aDate,
m_aIncrement.MinorTimeInterval.Number );
break;
}
+ if ( ! aDate.IsValid() || aDate == aTmpDate)
+ break;
}
}