sc/qa/unit/ucalc.cxx           |    4 ++++
 sc/source/core/data/table1.cxx |    6 ++----
 2 files changed, 6 insertions(+), 4 deletions(-)

New commits:
commit 8731701481de649a65d59e018d0ba0c381f670c3
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue May 30 11:34:21 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Jun 2 08:04:19 2023 +0200

    sc: fix bug in GetPrintAreaVer
    
    it should return false when checking a non-exising column.
    Since ad2bc869bfe2d34bde7d42e10593db1c5ffccc2a
    "tdf#50916 : Refactor table1.cxx wherever there is column access"
    
    Change-Id: I01a53f5fec7e2029badc5c23c1e26fc0723ba0ad
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152386
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index a1951cdc5b95..f966fdecea18 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -5269,6 +5269,10 @@ CPPUNIT_TEST_FIXTURE(Test, testAreasWithNotes)
     CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer found", dataFound);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("PrintAreaVer wrong row for notes", 
static_cast<SCROW>(2), row);
 
+    dataFound = m_pDoc->GetPrintAreaVer(0,20,21,row, bNotes); // cols 20 & 21
+    CPPUNIT_ASSERT_MESSAGE("PrintAreaVer found", !dataFound);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("PrintAreaVer wrong row for notes", 
static_cast<SCROW>(0), row);
+
     bNotes = false;
     dataFound = m_pDoc->GetPrintAreaVer(0,0,1,row, bNotes); // col 0 & 1
     CPPUNIT_ASSERT_MESSAGE("No PrintAreaVer should be found", !dataFound);
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 6cb5384c05f9..99e0c5f39b0d 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -756,13 +756,11 @@ bool ScTable::GetPrintAreaHor( SCROW nStartRow, SCROW 
nEndRow,
 bool ScTable::GetPrintAreaVer( SCCOL nStartCol, SCCOL nEndCol,
                                 SCROW& rEndRow, bool bNotes ) const
 {
-    nStartCol = std::min<SCCOL>( nStartCol, aCol.size()-1 );
-    nEndCol   = std::min<SCCOL>( nEndCol,   aCol.size()-1 );
     bool bFound = false;
     SCROW nMaxY = 0;
     SCCOL i;
 
-    for (i=nStartCol; i<=nEndCol; i++)              // Test attribute
+    for (i=nStartCol; i<=nEndCol && i < aCol.size(); i++)              // Test 
attribute
     {
         SCROW nLastRow;
         if (aCol[i].GetLastVisibleAttr( nLastRow ))
@@ -773,7 +771,7 @@ bool ScTable::GetPrintAreaVer( SCCOL nStartCol, SCCOL 
nEndCol,
         }
     }
 
-    for (i=nStartCol; i<=nEndCol; i++)              // Test data
+    for (i=nStartCol; i<=nEndCol && i < aCol.size(); i++)              // Test 
data
     {
         if (!aCol[i].IsEmptyData())
         {

Reply via email to