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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 3 20:22:13 UTC 2020


 sc/inc/address.hxx                |    2 -
 sc/source/core/tool/address.cxx   |    6 ++--
 sc/source/ui/inc/navipi.hxx       |    2 -
 sc/source/ui/navipi/navipi.cxx    |    6 ++--
 sc/source/ui/pagedlg/areasdlg.cxx |   50 +++++++++++++++++++-------------------
 sc/source/ui/unoobj/docuno.cxx    |    4 +--
 6 files changed, 35 insertions(+), 35 deletions(-)

New commits:
commit 5f6cd6272fbe9d6f4276021862442a3004657fb8
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Fri Jan 3 16:59:54 2020 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Jan 3 21:21:36 2020 +0100

    cid#1456608 Dereference after null check
    
    Change-Id: I47f41b1eae327a0140f4e59184db7a0d7f5b0f67
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86196
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/inc/address.hxx b/sc/inc/address.hxx
index 79af2eab6ca8..62117bfca254 100644
--- a/sc/inc/address.hxx
+++ b/sc/inc/address.hxx
@@ -988,7 +988,7 @@ inline OUString ScColToAlpha( SCCOL nCol )
 }
 
 /// get column number of A..IV... string
-bool AlphaToCol( const ScDocument* pDoc, SCCOL& rCol, const OUString& rStr);
+bool AlphaToCol(const ScDocument& rDoc, SCCOL& rCol, const OUString& rStr);
 
 #endif // INCLUDED_SC_INC_ADDRESS_HXX
 
diff --git a/sc/source/core/tool/address.cxx b/sc/source/core/tool/address.cxx
index 0ee1eeeb4862..94c06efc7c8d 100644
--- a/sc/source/core/tool/address.cxx
+++ b/sc/source/core/tool/address.cxx
@@ -2535,13 +2535,13 @@ OUString ScRefAddress::GetRefString( const ScDocument* pDoc, SCTAB nActTab,
     return aAdr.Format(nFlags, pDoc, rDetails);
 }
 
-bool AlphaToCol( const ScDocument* pDoc, SCCOL& rCol, const OUString& rStr)
+bool AlphaToCol(const ScDocument& rDoc, SCCOL& rCol, const OUString& rStr)
 {
     SCCOL nResult = 0;
     sal_Int32 nStop = rStr.getLength();
     sal_Int32 nPos = 0;
     sal_Unicode c;
-    const SCCOL nMaxCol = (pDoc ? pDoc->MaxCol() : MAXCOL);
+    const SCCOL nMaxCol = rDoc.MaxCol();
     while (nResult <= nMaxCol && nPos < nStop && (c = rStr[nPos]) != 0 &&
             rtl::isAsciiAlpha(c))
     {
@@ -2550,7 +2550,7 @@ bool AlphaToCol( const ScDocument* pDoc, SCCOL& rCol, const OUString& rStr)
         nResult += ScGlobal::ToUpperAlpha(c) - 'A';
         ++nPos;
     }
-    bool bOk = (pDoc->ValidCol(nResult) && nPos > 0);
+    bool bOk = (rDoc.ValidCol(nResult) && nPos > 0);
     if (bOk)
         rCol = nResult;
     return bOk;
diff --git a/sc/source/ui/inc/navipi.hxx b/sc/source/ui/inc/navipi.hxx
index 546c18a07c86..3ca20cbf5b90 100644
--- a/sc/source/ui/inc/navipi.hxx
+++ b/sc/source/ui/inc/navipi.hxx
@@ -134,7 +134,7 @@ private:
 
     void EvalText();
     void ExecuteCol();
-    static SCCOL AlphaToNum    ( const ScDocument* pDoc, OUString& rStr );
+    static SCCOL AlphaToNum    ( const ScDocument& rDoc, OUString& rStr );
     static SCCOL NumStrToAlpha ( OUString& rStr );
     static SCCOL NumToAlpha    ( SCCOL nColNo, OUString& rStr );
 };
diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx
index 464f523b0dca..947554ee96d3 100644
--- a/sc/source/ui/navipi/navipi.cxx
+++ b/sc/source/ui/navipi/navipi.cxx
@@ -164,7 +164,7 @@ void ColumnEdit::EvalText()
         else
         {
             ScTabViewShell* pViewSh = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current()  );
-            nCol = AlphaToNum( pViewSh->GetViewData().GetDocument(), aStrCol );
+            nCol = AlphaToNum( *pViewSh->GetViewData().GetDocument(), aStrCol );
         }
     }
     else
@@ -200,7 +200,7 @@ void ColumnEdit::SetCol( SCCOL nColNo )
     }
 }
 
-SCCOL ColumnEdit::AlphaToNum( const ScDocument* pDoc, OUString& rStr )
+SCCOL ColumnEdit::AlphaToNum( const ScDocument& rDoc, OUString& rStr )
 {
     SCCOL  nColumn = 0;
 
@@ -208,7 +208,7 @@ SCCOL ColumnEdit::AlphaToNum( const ScDocument* pDoc, OUString& rStr )
     {
         rStr = rStr.toAsciiUpperCase();
 
-        if (::AlphaToCol( pDoc, nColumn, rStr))
+        if (::AlphaToCol( rDoc, nColumn, rStr))
             ++nColumn;
 
         if ( (rStr.getLength() > SCNAV_COLLETTERS) || (nColumn > SCNAV_MAXCOL) )
diff --git a/sc/source/ui/pagedlg/areasdlg.cxx b/sc/source/ui/pagedlg/areasdlg.cxx
index f37f0ef1022f..791c4d1e696a 100644
--- a/sc/source/ui/pagedlg/areasdlg.cxx
+++ b/sc/source/ui/pagedlg/areasdlg.cxx
@@ -63,8 +63,8 @@ namespace
 
 // global functions (->at the end of the file):
 
-static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument* pDoc, bool bIsRow, ScRange* pRange );
-static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument* pDoc, bool bIsRow, OUString& rStr );
+static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument& rDoc, bool bIsRow, ScRange* pRange );
+static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument& rDoc, bool bIsRow, OUString& rStr );
 
 #if 0
 // this method is useful when debugging address flags.
@@ -187,7 +187,7 @@ void ScPrintAreasDlg::SetReference( const ScRange& rRef, ScDocument& /* rDoc */
         else
         {
             bool bRow = ( m_xEdRepeatRow.get() == m_pRefInputEdit );
-            lcl_GetRepeatRangeString(&rRef, pDoc, bRow, aStr);
+            lcl_GetRepeatRangeString(&rRef, *pDoc, bRow, aStr);
             m_pRefInputEdit->SetRefString( aStr );
         }
         Impl_ModifyHdl( *m_pRefInputEdit );
@@ -275,12 +275,12 @@ void ScPrintAreasDlg::Impl_Reset()
 
     // repeat row
 
-    lcl_GetRepeatRangeString(pRepeatRowRange, pDoc, true, aStrRange);
+    lcl_GetRepeatRangeString(pRepeatRowRange, *pDoc, true, aStrRange);
     m_xEdRepeatRow->SetText( aStrRange );
 
     // repeat column
 
-    lcl_GetRepeatRangeString(pRepeatColRange, pDoc, false, aStrRange);
+    lcl_GetRepeatRangeString(pRepeatColRange, *pDoc, false, aStrRange);
     m_xEdRepeatCol->SetText( aStrRange );
 
     Impl_ModifyHdl( *m_xEdPrintArea );
@@ -303,7 +303,7 @@ bool ScPrintAreasDlg::Impl_GetItem( const formula::RefEdit* pEd, SfxStringItem&
     {
         ScRange aRange;
         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
-        lcl_CheckRepeatString(aRangeStr, pDoc, m_xEdRepeatRow.get() == pEd, &aRange);
+        lcl_CheckRepeatString(aRangeStr, *pDoc, m_xEdRepeatRow.get() == pEd, &aRange);
         aRangeStr = aRange.Format(*pDoc, ScRefFlags::RANGE_ABS, eConv);
     }
 
@@ -347,11 +347,11 @@ bool ScPrintAreasDlg::Impl_CheckRefStrings()
 
     bool bRepeatRowOk = aStrRepeatRow.isEmpty();
     if ( !bRepeatRowOk )
-        bRepeatRowOk = lcl_CheckRepeatString(aStrRepeatRow, pDoc, true, nullptr);
+        bRepeatRowOk = lcl_CheckRepeatString(aStrRepeatRow, *pDoc, true, nullptr);
 
     bool bRepeatColOk = aStrRepeatCol.isEmpty();
     if ( !bRepeatColOk )
-        bRepeatColOk = lcl_CheckRepeatString(aStrRepeatCol, pDoc, false, nullptr);
+        bRepeatColOk = lcl_CheckRepeatString(aStrRepeatCol, *pDoc, false, nullptr);
 
     // error messages
 
@@ -429,13 +429,13 @@ void ScPrintAreasDlg::Impl_FillLists()
 
             if (rEntry.second->HasType(ScRangeData::Type::RowHeader))
             {
-                lcl_GetRepeatRangeString(&aRange, pDoc, true, aSymbol);
+                lcl_GetRepeatRangeString(&aRange, *pDoc, true, aSymbol);
                 m_xLbRepeatRow->append(aSymbol, aName);
             }
 
             if (rEntry.second->HasType(ScRangeData::Type::ColHeader))
             {
-                lcl_GetRepeatRangeString(&aRange, pDoc, false, aSymbol);
+                lcl_GetRepeatRangeString(&aRange, *pDoc, false, aSymbol);
                 m_xLbRepeatCol->append(aSymbol, aName);
             }
         }
@@ -584,7 +584,7 @@ IMPL_LINK( ScPrintAreasDlg, Impl_ModifyHdl, formula::RefEdit&, rEd, void )
 
 // TODO: It might make sense to move these functions to address.?xx. -kohei
 
-static bool lcl_CheckOne_OOO( const ScDocument* pDoc, const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
+static bool lcl_CheckOne_OOO( const ScDocument& rDoc, const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
 {
     // Allowed syntax for rStr:
     // Row: [$]1-MAXTAB
@@ -616,7 +616,7 @@ static bool lcl_CheckOne_OOO( const ScDocument* pDoc, const OUString& rStr, bool
         else
         {
             SCCOL nCol = 0;
-            bStrOk = ::AlphaToCol( pDoc, nCol, aStr);
+            bStrOk = ::AlphaToCol(rDoc, nCol, aStr);
             nNum = nCol;
         }
     }
@@ -627,10 +627,10 @@ static bool lcl_CheckOne_OOO( const ScDocument* pDoc, const OUString& rStr, bool
     return bStrOk;
 }
 
-static bool lcl_CheckOne_XL_A1( const ScDocument* pDoc, const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
+static bool lcl_CheckOne_XL_A1( const ScDocument& rDoc, const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
 {
     // XL A1 style is identical to OOO one for print range formats.
-    return lcl_CheckOne_OOO(pDoc, rStr, bIsRow, rVal);
+    return lcl_CheckOne_OOO(rDoc, rStr, bIsRow, rVal);
 }
 
 static bool lcl_CheckOne_XL_R1C1( const OUString& rStr, bool bIsRow, SCCOLROW& rVal )
@@ -661,14 +661,14 @@ static bool lcl_CheckOne_XL_R1C1( const OUString& rStr, bool bIsRow, SCCOLROW& r
     return true;
 }
 
-static bool lcl_CheckRepeatOne( const ScDocument* pDoc, const OUString& rStr, formula::FormulaGrammar::AddressConvention eConv, bool bIsRow, SCCOLROW& rVal )
+static bool lcl_CheckRepeatOne( const ScDocument& rDoc, const OUString& rStr, formula::FormulaGrammar::AddressConvention eConv, bool bIsRow, SCCOLROW& rVal )
 {
     switch (eConv)
     {
         case formula::FormulaGrammar::CONV_OOO:
-            return lcl_CheckOne_OOO(pDoc, rStr, bIsRow, rVal);
+            return lcl_CheckOne_OOO(rDoc, rStr, bIsRow, rVal);
         case formula::FormulaGrammar::CONV_XL_A1:
-            return lcl_CheckOne_XL_A1(pDoc, rStr, bIsRow, rVal);
+            return lcl_CheckOne_XL_A1(rDoc, rStr, bIsRow, rVal);
         case formula::FormulaGrammar::CONV_XL_R1C1:
             return lcl_CheckOne_XL_R1C1(rStr, bIsRow, rVal);
         default:
@@ -679,12 +679,12 @@ static bool lcl_CheckRepeatOne( const ScDocument* pDoc, const OUString& rStr, fo
     return false;
 }
 
-static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument* pDoc, bool bIsRow, ScRange* pRange )
+static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument& rDoc, bool bIsRow, ScRange* pRange )
 {
     // Row: [valid row] rsep [valid row]
     // Col: [valid col] rsep [valid col]
 
-    const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
+    const formula::FormulaGrammar::AddressConvention eConv = rDoc.GetAddressConvention();
     const sal_Unicode rsep = ScCompiler::GetNativeSymbolChar(ocRange);
 
     if (pRange)
@@ -713,7 +713,7 @@ static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument* pDoc,
             if (aBuf.isEmpty())
                 return false;
 
-            bool bRes = lcl_CheckRepeatOne(pDoc, aBuf, eConv, bIsRow, nVal);
+            bool bRes = lcl_CheckRepeatOne(rDoc, aBuf, eConv, bIsRow, nVal);
             if (!bRes)
                 return false;
 
@@ -740,7 +740,7 @@ static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument* pDoc,
 
     if (!aBuf.isEmpty())
     {
-        bool bRes = lcl_CheckRepeatOne(pDoc, aBuf, eConv, bIsRow, nVal);
+        bool bRes = lcl_CheckRepeatOne(rDoc, aBuf, eConv, bIsRow, nVal);
         if (!bRes)
             return false;
 
@@ -764,24 +764,24 @@ static bool lcl_CheckRepeatString( const OUString& rStr, const ScDocument* pDoc,
     return true;
 }
 
-static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument* pDoc, bool bIsRow, OUString& rStr )
+static void lcl_GetRepeatRangeString( const ScRange* pRange, const ScDocument& rDoc, bool bIsRow, OUString& rStr )
 {
     rStr.clear();
     if (!pRange)
         return;
 
-    const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
+    const formula::FormulaGrammar::AddressConvention eConv = rDoc.GetAddressConvention();
     const ScAddress& rStart = pRange->aStart;
     const ScAddress& rEnd   = pRange->aEnd;
 
     const ScRefFlags nFmt = bIsRow
                             ? (ScRefFlags::ROW_VALID | ScRefFlags::ROW_ABS)
                             : (ScRefFlags::COL_VALID | ScRefFlags::COL_ABS);
-    rStr += rStart.Format(nFmt, pDoc, eConv);
+    rStr += rStart.Format(nFmt, &rDoc, eConv);
     if ((bIsRow && rStart.Row() != rEnd.Row()) || (!bIsRow && rStart.Col() != rEnd.Col()))
     {
         rStr += ScCompiler::GetNativeSymbol(ocRange);
-        rStr += rEnd.Format(nFmt, pDoc, eConv);
+        rStr += rEnd.Format(nFmt, &rDoc, eConv);
     }
 }
 
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 7877fdd30bcf..347102005723 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -3866,7 +3866,7 @@ ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(sal_Int32 nIndex) con
 ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const OUString& aName) const
 {
     SCCOL nCol = 0;
-    if ( ::AlphaToCol( &pDocShell->GetDocument(), nCol, aName) )
+    if ( ::AlphaToCol( pDocShell->GetDocument(), nCol, aName) )
         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
             return new ScTableColumnObj( pDocShell, nCol, nTab );
 
@@ -3976,7 +3976,7 @@ sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const OUString& aName )
 {
     SolarMutexGuard aGuard;
     SCCOL nCol = 0;
-    if ( ::AlphaToCol( &pDocShell->GetDocument(), nCol, aName) )
+    if ( ::AlphaToCol( pDocShell->GetDocument(), nCol, aName) )
         if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol )
             return true;
 


More information about the Libreoffice-commits mailing list