[Libreoffice-commits] core.git: chart2/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 16 11:33:06 UTC 2019


 chart2/source/view/charttypes/VSeriesPlotter.cxx |   67 ++++++++++++-----------
 1 file changed, 36 insertions(+), 31 deletions(-)

New commits:
commit eca99b2dec0219893eaefa231b789cf6bab838ac
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Jul 15 21:42:04 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Jul 16 13:32:15 2019 +0200

    cid#1448243 Using invalid iterator
    
    return early on error paths
    
    Change-Id: I5d4f05585bb8c4b7d3fbe6824b8aa97785098ec5
    Reviewed-on: https://gerrit.libreoffice.org/75662
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index 835c19a449ad..e95961677d42 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -1605,41 +1605,46 @@ void VSeriesPlotter::setTimeResolutionOnXAxis( long TimeResolution, const Date&
 long VSeriesPlotter::calculateTimeResolutionOnXAxis()
 {
     long nRet = css::chart::TimeUnit::YEAR;
-    if( m_pExplicitCategoriesProvider )
-    {
-        const std::vector< double >&  rDateCategories = m_pExplicitCategoriesProvider->getDateCategories();
-        Date aNullDate(30,12,1899);
-        if (m_apNumberFormatterWrapper)
-            aNullDate = m_apNumberFormatterWrapper->getNullDate();
-        if( !rDateCategories.empty() )
-        {
-            std::vector< double >::const_iterator aIt = rDateCategories.begin(), aEnd = rDateCategories.end();
-            aIt = std::find_if(aIt, aEnd, [](const double& rDateCategory) { return !rtl::math::isNan(rDateCategory); });
+    if (!m_pExplicitCategoriesProvider)
+        return nRet;
 
-            Date aPrevious(aNullDate); aPrevious.AddDays(rtl::math::approxFloor(*aIt));
-            ++aIt;
-            for(;aIt!=aEnd;++aIt)
-            {
-                if (rtl::math::isNan(*aIt))
-                    continue;
+    const std::vector<double>& rDateCategories = m_pExplicitCategoriesProvider->getDateCategories();
+    if (rDateCategories.empty())
+        return nRet;
 
-                Date aCurrent(aNullDate); aCurrent.AddDays(rtl::math::approxFloor(*aIt));
-                if( nRet == css::chart::TimeUnit::YEAR )
-                {
-                    if( DateHelper::IsInSameYear( aPrevious, aCurrent ) )
-                        nRet = css::chart::TimeUnit::MONTH;
-                }
-                if( nRet == css::chart::TimeUnit::MONTH )
-                {
-                    if( DateHelper::IsInSameMonth( aPrevious, aCurrent ) )
-                        nRet = css::chart::TimeUnit::DAY;
-                }
-                if( nRet == css::chart::TimeUnit::DAY )
-                    break;
-                aPrevious=aCurrent;
-            }
+    std::vector<double>::const_iterator aIt = rDateCategories.begin(), aEnd = rDateCategories.end();
+
+    aIt = std::find_if(aIt, aEnd, [](const double& rDateCategory) { return !rtl::math::isNan(rDateCategory); });
+    if (aIt == aEnd)
+        return nRet;
+
+    Date aNullDate(30,12,1899);
+    if (m_apNumberFormatterWrapper)
+        aNullDate = m_apNumberFormatterWrapper->getNullDate();
+
+    Date aPrevious(aNullDate); aPrevious.AddDays(rtl::math::approxFloor(*aIt));
+    ++aIt;
+    for(;aIt!=aEnd;++aIt)
+    {
+        if (rtl::math::isNan(*aIt))
+            continue;
+
+        Date aCurrent(aNullDate); aCurrent.AddDays(rtl::math::approxFloor(*aIt));
+        if( nRet == css::chart::TimeUnit::YEAR )
+        {
+            if( DateHelper::IsInSameYear( aPrevious, aCurrent ) )
+                nRet = css::chart::TimeUnit::MONTH;
+        }
+        if( nRet == css::chart::TimeUnit::MONTH )
+        {
+            if( DateHelper::IsInSameMonth( aPrevious, aCurrent ) )
+                nRet = css::chart::TimeUnit::DAY;
         }
+        if( nRet == css::chart::TimeUnit::DAY )
+            break;
+        aPrevious=aCurrent;
     }
+
     return nRet;
 }
 double VSeriesPlotter::getMinimumX()


More information about the Libreoffice-commits mailing list