sc/inc/columniterator.hxx              |    1 +
 sc/qa/unit/ucalc.cxx                   |   18 ++++++++++++++++++
 sc/qa/unit/ucalc.hxx                   |    2 ++
 sc/source/core/data/columniterator.cxx |   10 +++++++---
 4 files changed, 28 insertions(+), 3 deletions(-)

New commits:
commit fdef3ecc1ddef7adcf51df465048613b7b3e4ae6
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Thu Jul 12 21:01:35 2018 +0100

    tdf#118620 - unit test.
    
    Change-Id: Iae7d2f5cc1ed5b37d6b7ced983951a64e2114c2b
    Reviewed-on: https://gerrit.libreoffice.org/57369
    Tested-by: Jenkins
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 826f846279f2..9605b9094cff 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -1,3 +1,4 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /*
  * This file is part of the LibreOffice project.
  *
@@ -441,6 +442,23 @@ void Test::testInput()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testColumnIterator() // tdf#118620
+{
+    CPPUNIT_ASSERT_MESSAGE ("failed to insert sheet",
+                            m_pDoc->InsertTab (0, "foo"));
+
+    m_pDoc->SetString(0, 0, 0, "'10.5");
+    m_pDoc->SetString(0, MAXROW-5, 0, "42.0");
+    std::unique_ptr<sc::ColumnIterator> it = m_pDoc->GetColumnIterator(0, 0, 
MAXROW - 10, MAXROW);
+    while (it->hasCell())
+    {
+        it->getCell();
+        it->next();
+    }
+
+    m_pDoc->DeleteTab(0);
+}
+
 void Test::testDocStatistics()
 {
     SCTAB nStartTabs = m_pDoc->GetTableCount();
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 03305a8ad74e..a81a452c494c 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -117,6 +117,7 @@ public:
     void testRangeList();
     void testMarkData();
     void testInput();
+    void testColumnIterator();
     void testDocStatistics();
     void testRowForHeight();
 
@@ -557,6 +558,7 @@ public:
     CPPUNIT_TEST(testRangeList);
     CPPUNIT_TEST(testMarkData);
     CPPUNIT_TEST(testInput);
+    CPPUNIT_TEST(testColumnIterator);
     CPPUNIT_TEST(testDocStatistics);
     CPPUNIT_TEST(testRowForHeight);
     CPPUNIT_TEST(testDataEntries);
commit d3387b38fe0eea3fb7ac630c026f02986e8dafc4
Author: Michael Meeks <michael.me...@collabora.com>
Date:   Thu Jul 12 19:06:03 2018 +0100

    tdf#118620 - avoid out of bounds iterator for end of sheet pivots.
    
    Change-Id: I2ddcf56dc94175718739611f0791558fda87b1ba
    Reviewed-on: https://gerrit.libreoffice.org/57358
    Tested-by: Jenkins
    Reviewed-by: Kohei Yoshida <libreoff...@kohei.us>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>

diff --git a/sc/inc/columniterator.hxx b/sc/inc/columniterator.hxx
index c964e0ccb9c9..b62510ac380a 100644
--- a/sc/inc/columniterator.hxx
+++ b/sc/inc/columniterator.hxx
@@ -67,6 +67,7 @@ class ColumnIterator
 {
     CellStoreType::const_position_type maPos;
     CellStoreType::const_position_type maPosEnd;
+    bool mbComplete;
 
 public:
     ColumnIterator( const CellStoreType& rCells, SCROW nRow1, SCROW nRow2 );
diff --git a/sc/source/core/data/columniterator.cxx 
b/sc/source/core/data/columniterator.cxx
index 819f8466768d..7f3048d3661b 100644
--- a/sc/source/core/data/columniterator.cxx
+++ b/sc/source/core/data/columniterator.cxx
@@ -171,7 +171,8 @@ namespace sc {
 
 ColumnIterator::ColumnIterator( const CellStoreType& rCells, SCROW nRow1, 
SCROW nRow2 ) :
     maPos(rCells.position(nRow1)),
-    maPosEnd(rCells.position(maPos.first, nRow2+1))
+    maPosEnd(rCells.position(maPos.first, nRow2)),
+    mbComplete(false)
 {
 }
 
@@ -179,7 +180,10 @@ ColumnIterator::~ColumnIterator() {}
 
 void ColumnIterator::next()
 {
-    maPos = CellStoreType::next_position(maPos);
+    if ( maPos == maPosEnd)
+        mbComplete = true;
+    else
+        maPos = CellStoreType::next_position(maPos);
 }
 
 SCROW ColumnIterator::getRow() const
@@ -189,7 +193,7 @@ SCROW ColumnIterator::getRow() const
 
 bool ColumnIterator::hasCell() const
 {
-    return maPos != maPosEnd;
+    return !mbComplete;
 }
 
 mdds::mtv::element_t ColumnIterator::getType() const
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to