[Libreoffice-commits] core.git: sc/inc sc/source

Bartosz Kosiorek gang65 at poczta.onet.pl
Wed Feb 8 20:07:04 UTC 2017


 sc/inc/table.hxx               |   13 +++++++++++
 sc/source/core/data/table1.cxx |   47 ++++++++++++++++++++++-------------------
 sc/source/core/data/table3.cxx |   14 ++++++------
 sc/source/core/data/table6.cxx |    6 ++---
 4 files changed, 49 insertions(+), 31 deletions(-)

New commits:
commit b78c6d8efd9531243e62a388bffc3f071d9a56eb
Author: Bartosz Kosiorek <gang65 at poczta.onet.pl>
Date:   Mon Jan 16 22:57:51 2017 +0100

    tdf#50916 Introduce new column validation function
    
    Change-Id: Ib8f7b3793732a113e764c4345c07803eb8bcbc3f
    Reviewed-on: https://gerrit.libreoffice.org/33196
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 34f6e3f..3d446ad 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -265,6 +265,19 @@ public:
     bool        IsStreamValid() const                        { return bStreamValid; }
     void        SetStreamValid( bool bSet, bool bIgnoreLock = false );
 
+    SAL_WARN_UNUSED_RESULT inline bool IsColValid( SCCOL nScCol ) const
+    {
+        return nScCol >= static_cast< SCCOL >( 0 ) && nScCol < aCol.size();
+    }
+    SAL_WARN_UNUSED_RESULT inline bool IsColRowValid( SCCOL nScCol, SCROW nScRow ) const
+    {
+        return IsColValid( nScCol ) && ValidRow( nScRow );
+    }
+    SAL_WARN_UNUSED_RESULT inline bool IsColRowTabValid( SCCOL nScCol, SCROW nScRow, SCTAB nScTab ) const
+    {
+        return IsColValid( nScCol ) && ValidRow( nScRow ) && ValidTab( nScTab );
+    }
+
     bool        IsPendingRowHeights() const                  { return bPendingRowHeights; }
     void        SetPendingRowHeights( bool bSet );
 
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 289266b..bb899e5 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -328,7 +328,7 @@ ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const OUString& rNewName,
         }
     }
 
-    for (SCCOL k=0; k<=MAXCOL; k++)
+    for (SCCOL k=0; k < aCol.size(); k++)
         aCol[k].Init( k, nTab, pDocument, true );
 }
 
@@ -1039,13 +1039,10 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS
 
 SCROW ScTable::GetLastDataRow( SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const
 {
-    if (!ValidCol(nCol1) || !ValidCol(nCol2))
+    if ( !IsColValid( nCol1 ) || !ValidCol( nCol2 ) )
         return -1;
 
-    if ( nCol1 >= aCol.size() )
-        return -1;
-
-    nCol2 = std::min<SCCOL>( nCol2, aCol.size()-1 );
+    nCol2 = std::min<SCCOL>( nCol2, aCol.size() - 1 );
 
     SCROW nNewLastRow = 0;
     for (SCCOL i = nCol1; i <= nCol2; ++i)
@@ -1778,7 +1775,7 @@ void ScTable::SetTabNo(SCTAB nNewTab)
 void ScTable::FindRangeNamesInUse(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                                sc::UpdatedRangeNames& rIndexes) const
 {
-    for (SCCOL i = nCol1; i <= nCol2 && ValidCol(i); i++)
+    for (SCCOL i = nCol1; i <= nCol2 && IsColValid( i ); i++)
         aCol[i].FindRangeNamesInUse(nRow1, nRow2, rIndexes);
 }
 
@@ -2178,7 +2175,7 @@ sal_uLong ScTable::AddCondFormat( ScConditionalFormat* pNew )
 
 SvtScriptType ScTable::GetScriptType( SCCOL nCol, SCROW nRow ) const
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return SvtScriptType::NONE;
 
     return aCol[nCol].GetScriptType(nRow);
@@ -2195,7 +2192,7 @@ void ScTable::SetScriptType( SCCOL nCol, SCROW nRow, SvtScriptType nType )
 SvtScriptType ScTable::GetRangeScriptType(
     sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow1, SCROW nRow2 )
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return SvtScriptType::NONE;
 
     sc::CellStoreType::iterator itr = aCol[nCol].maCells.begin();
@@ -2204,7 +2201,7 @@ SvtScriptType ScTable::GetRangeScriptType(
 
 size_t ScTable::GetFormulaHash( SCCOL nCol, SCROW nRow ) const
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return 0;
 
     return aCol[nCol].GetFormulaHash(nRow);
@@ -2212,7 +2209,7 @@ size_t ScTable::GetFormulaHash( SCCOL nCol, SCROW nRow ) const
 
 ScFormulaVectorState ScTable::GetFormulaVectorState( SCCOL nCol, SCROW nRow ) const
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return FormulaVectorUnknown;
 
     return aCol[nCol].GetFormulaVectorState(nRow);
@@ -2220,9 +2217,11 @@ ScFormulaVectorState ScTable::GetFormulaVectorState( SCCOL nCol, SCROW nRow ) co
 
 formula::FormulaTokenRef ScTable::ResolveStaticReference( SCCOL nCol, SCROW nRow )
 {
-    if (!ValidCol(nCol) || !ValidRow(nRow))
+    if ( !ValidCol( nCol ) || !ValidRow( nRow ) )
         return formula::FormulaTokenRef();
-
+    if ( nCol >= aCol.size() )
+        // Return a value of 0.0 if column not exists
+        return formula::FormulaTokenRef(new formula::FormulaDoubleToken(0.0));
     return aCol[nCol].ResolveStaticReference(nRow);
 }
 
@@ -2231,11 +2230,17 @@ formula::FormulaTokenRef ScTable::ResolveStaticReference( SCCOL nCol1, SCROW nRo
     if (nCol2 < nCol1 || nRow2 < nRow1)
         return formula::FormulaTokenRef();
 
-    if (!ValidCol(nCol1) || !ValidCol(nCol2) || !ValidRow(nRow1) || !ValidRow(nRow2))
+    if ( !ValidCol( nCol1 ) || !ValidCol( nCol2 ) || !ValidRow( nRow1 ) || !ValidRow( nRow2 ) )
         return formula::FormulaTokenRef();
 
+    SCCOL nMaxCol;
+    if ( nCol2 >= aCol.size() )
+        nMaxCol = aCol.size() - 1;
+    else
+        nMaxCol = nCol2;
+
     ScMatrixRef pMat(new ScFullMatrix(nCol2-nCol1+1, nRow2-nRow1+1, 0.0));
-    for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+    for (SCCOL nCol = nCol1; nCol <= nMaxCol; ++nCol)
     {
         if (!aCol[nCol].ResolveStaticReference(*pMat, nCol2-nCol1, nRow1, nRow2))
             // Column contains non-static cell. Failed.
@@ -2250,7 +2255,7 @@ formula::VectorRefArray ScTable::FetchVectorRefArray( SCCOL nCol, SCROW nRow1, S
     if (nRow2 < nRow1)
         return formula::VectorRefArray();
 
-    if (!ValidCol(nCol) || !ValidRow(nRow1) || !ValidRow(nRow2))
+    if ( !IsColValid( nCol ) || !ValidRow( nRow1 ) || !ValidRow( nRow2 ) )
         return formula::VectorRefArray();
 
     return aCol[nCol].FetchVectorRefArray(nRow1, nRow2);
@@ -2258,7 +2263,7 @@ formula::VectorRefArray ScTable::FetchVectorRefArray( SCCOL nCol, SCROW nRow1, S
 
 ScRefCellValue ScTable::GetRefCellValue( SCCOL nCol, SCROW nRow )
 {
-    if (!ValidColRow(nCol, nRow))
+    if ( !IsColRowValid( nCol, nRow ) )
         return ScRefCellValue();
 
     return aCol[nCol].GetCellValue(nRow);
@@ -2266,7 +2271,7 @@ ScRefCellValue ScTable::GetRefCellValue( SCCOL nCol, SCROW nRow )
 
 SvtBroadcaster* ScTable::GetBroadcaster( SCCOL nCol, SCROW nRow )
 {
-    if (!ValidColRow(nCol, nRow))
+    if ( !IsColRowValid( nCol, nRow ) )
         return nullptr;
 
     return aCol[nCol].GetBroadcaster(nRow);
@@ -2275,7 +2280,7 @@ SvtBroadcaster* ScTable::GetBroadcaster( SCCOL nCol, SCROW nRow )
 void ScTable::DeleteBroadcasters(
     sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow1, SCROW nRow2 )
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return;
 
     aCol[nCol].DeleteBroadcasters(rBlockPos, nRow1, nRow2);
@@ -2314,7 +2319,7 @@ void ScTable::SetFormulaResults(
 #if DUMP_COLUMN_STORAGE
 void ScTable::DumpColumnStorage( SCCOL nCol ) const
 {
-    if (!ValidCol(nCol))
+    if ( !IsColValid( nCol ) )
         return;
 
     aCol[nCol].DumpColumnStorage();
@@ -2323,7 +2328,7 @@ void ScTable::DumpColumnStorage( SCCOL nCol ) const
 
 const SvtBroadcaster* ScTable::GetBroadcaster( SCCOL nCol, SCROW nRow ) const
 {
-    if (!ValidColRow(nCol, nRow))
+    if ( !IsColRowValid( nCol, nRow ) )
         return nullptr;
 
     return aCol[nCol].GetBroadcaster(nRow);
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 17cc5b3..db2c8de 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -3402,7 +3402,7 @@ sal_uLong ScTable::GetCellCount() const
 {
     sal_uLong nCellCount = 0;
 
-    for ( SCCOL nCol=0; nCol<=MAXCOL; nCol++ )
+    for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ )
         nCellCount += aCol[nCol].GetCellCount();
 
     return nCellCount;
@@ -3412,8 +3412,8 @@ sal_uLong ScTable::GetWeightedCount() const
 {
     sal_uLong nCellCount = 0;
 
-    for ( SCCOL nCol=0; nCol<=MAXCOL; nCol++ )
-        if ( aCol[nCol].GetCellCount() )                    // GetCellCount ist inline
+    for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ )
+        if ( aCol[nCol].GetCellCount() )
             nCellCount += aCol[nCol].GetWeightedCount();
 
     return nCellCount;
@@ -3423,8 +3423,8 @@ sal_uLong ScTable::GetCodeCount() const
 {
     sal_uLong nCodeCount = 0;
 
-    for ( SCCOL nCol=0; nCol<=MAXCOL; nCol++ )
-        if ( aCol[nCol].GetCellCount() )                    // GetCellCount ist inline
+    for ( SCCOL nCol=0; nCol < aCol.size(); nCol++ )
+        if ( aCol[nCol].GetCellCount() )
             nCodeCount += aCol[nCol].GetCodeCount();
 
     return nCodeCount;
@@ -3433,7 +3433,7 @@ sal_uLong ScTable::GetCodeCount() const
 sal_Int32 ScTable::GetMaxStringLen( SCCOL nCol, SCROW nRowStart,
         SCROW nRowEnd, rtl_TextEncoding eCharSet ) const
 {
-    if ( ValidCol(nCol) )
+    if ( IsColValid( nCol ) )
         return aCol[nCol].GetMaxStringLen( nRowStart, nRowEnd, eCharSet );
     else
         return 0;
@@ -3442,7 +3442,7 @@ sal_Int32 ScTable::GetMaxStringLen( SCCOL nCol, SCROW nRowStart,
 sal_Int32 ScTable::GetMaxNumberStringLen(
     sal_uInt16& nPrecision, SCCOL nCol, SCROW nRowStart, SCROW nRowEnd ) const
 {
-    if ( ValidCol(nCol) )
+    if ( IsColValid( nCol ) )
         return aCol[nCol].GetMaxNumberStringLen( nPrecision, nRowStart, nRowEnd );
     else
         return 0;
diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx
index 9539311..7cf1557 100644
--- a/sc/source/core/data/table6.cxx
+++ b/sc/source/core/data/table6.cxx
@@ -52,7 +52,7 @@ bool lcl_GetTextWithBreaks( const EditTextObject& rData, ScDocument* pDoc, OUStr
 bool ScTable::SearchCell(const SvxSearchItem& rSearchItem, SCCOL nCol, SCROW nRow,
                          const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc)
 {
-    if (!ValidColRow( nCol, nRow))
+    if ( !IsColRowValid( nCol, nRow ) )
         return false;
 
     bool    bFound = false;
@@ -609,7 +609,7 @@ bool ScTable::SearchStyle(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW&
 
     if (bRows)                                      // by row
     {
-        if (!ValidCol(nCol))
+        if ( !IsColValid( nCol ) )
         {
             SAL_WARN( "sc.core", "SearchStyle: bad column " << nCol);
             return false;
@@ -629,7 +629,7 @@ bool ScTable::SearchStyle(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW&
                 bFound = true;
             }
         }
-        while (!bFound && ValidCol(nCol));
+        while ( !bFound && IsColValid( nCol ) );
     }
     else                                    // by column
     {


More information about the Libreoffice-commits mailing list