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

Eike Rathke erack at redhat.com
Thu May 8 16:21:35 PDT 2014


 sc/inc/consoli.hxx              |    7 ++---
 sc/source/core/tool/consoli.cxx |   52 ++++++++++++++--------------------------
 2 files changed, 22 insertions(+), 37 deletions(-)

New commits:
commit e891afeccba8f20f8bdaeacb20f2215cfcb1abfd
Author: Eike Rathke <erack at redhat.com>
Date:   Fri May 9 00:11:06 2014 +0200

    resolve fdo#77509 memory corruption / crash in Consolidate
    
    Regression introduced with c81dec478ab0618f2acd2580654a93d3a7185444
    memcpy some sizeof(OUString) is doomed to fail.
    
    Change-Id: I81dc9cc7eaf02607ed05b4d284a7e5e462eeeb0a

diff --git a/sc/inc/consoli.hxx b/sc/inc/consoli.hxx
index ec96a60..8811f5b 100644
--- a/sc/inc/consoli.hxx
+++ b/sc/inc/consoli.hxx
@@ -80,11 +80,10 @@ private:
     double**            ppCount;
     double**            ppSumSqr;
     ScReferenceList**   ppRefs;
-    OUString*           mpColHeaders;
-    OUString*           mpRowHeaders;
+    ::std::vector<OUString> maColHeaders;
+    ::std::vector<OUString> maRowHeaders;
+    ::std::vector<OUString> maTitles;
     SCSIZE              nDataCount;
-    SCSIZE              nTitleCount;
-    OUString*           mpTitles;
     SCSIZE**            ppTitlePos;
     bool                bCornerUsed;
     OUString            aCornerText;        // only for bColByName && bRowByName
diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx
index 7c897c0..5a36fba 100644
--- a/sc/source/core/tool/consoli.cxx
+++ b/sc/source/core/tool/consoli.cxx
@@ -71,16 +71,9 @@ void ScReferenceList::AddEntry( SCCOL nCol, SCROW nRow, SCTAB nTab )
 }
 
 template< typename T >
-static void lcl_AddString( OUString*& pData, T& nCount, const OUString& rInsert )
+static void lcl_AddString( ::std::vector<OUString>& rData, T& nCount, const OUString& rInsert )
 {
-    OUString* pOldData = pData;
-    pData = new OUString[ nCount+1 ];
-    if (pOldData)
-    {
-        memcpy( pData, pOldData, nCount * sizeof(OUString) );
-        delete[] pOldData;
-    }
-    pData[nCount] = rInsert;
+    rData.push_back( rInsert);
     ++nCount;
 }
 
@@ -96,11 +89,7 @@ ScConsData::ScConsData() :
     ppCount(NULL),
     ppSumSqr(NULL),
     ppRefs(NULL),
-    mpColHeaders(NULL),
-    mpRowHeaders(NULL),
     nDataCount(0),
-    nTitleCount(0),
-    mpTitles(NULL),
     ppTitlePos(NULL),
     bCornerUsed(false)
 {
@@ -141,16 +130,12 @@ void ScConsData::DeleteData()
     DELETEARR( ppSumSqr,nColCount );
     DELETEARR( ppUsed,  nColCount );                // erst nach ppRefs !!!
     DELETEARR( ppTitlePos, nRowCount );
-    delete[] mpColHeaders;
-    mpColHeaders = NULL;
-    delete[] mpRowHeaders;
-    mpRowHeaders = NULL;
-    delete[] mpTitles;
-    mpTitles = NULL;
-    nTitleCount = 0;
+    ::std::vector<OUString>().swap( maColHeaders);
+    ::std::vector<OUString>().swap( maRowHeaders);
+    ::std::vector<OUString>().swap( maTitles);
     nDataCount = 0;
 
-    if (bColByName) nColCount = 0;                  // sonst stimmt mpColHeaders nicht
+    if (bColByName) nColCount = 0;                  // sonst stimmt maColHeaders nicht
     if (bRowByName) nRowCount = 0;
 
     bCornerUsed = false;
@@ -254,10 +239,10 @@ void ScConsData::AddFields( ScDocument* pSrcDoc, SCTAB nTab,
             {
                 bool bFound = false;
                 for (SCSIZE i=0; i<nColCount && !bFound; i++)
-                    if ( mpColHeaders[i] == aTitle )
+                    if ( maColHeaders[i] == aTitle )
                         bFound = true;
                 if (!bFound)
-                    lcl_AddString( mpColHeaders, nColCount, aTitle );
+                    lcl_AddString( maColHeaders, nColCount, aTitle );
             }
         }
     }
@@ -271,10 +256,10 @@ void ScConsData::AddFields( ScDocument* pSrcDoc, SCTAB nTab,
             {
                 bool bFound = false;
                 for (SCSIZE i=0; i<nRowCount && !bFound; i++)
-                    if ( mpRowHeaders[i] == aTitle )
+                    if ( maRowHeaders[i] == aTitle )
                         bFound = true;
                 if (!bFound)
-                    lcl_AddString( mpRowHeaders, nRowCount, aTitle );
+                    lcl_AddString( maRowHeaders, nRowCount, aTitle );
             }
         }
     }
@@ -287,7 +272,8 @@ void ScConsData::AddName( const OUString& rName )
 
     if (bReference)
     {
-        lcl_AddString( mpTitles, nTitleCount, rName );
+        maTitles.push_back( rName);
+        size_t nTitleCount = maTitles.size();
 
         for (nArrY=0; nArrY<nRowCount; nArrY++)
         {
@@ -526,7 +512,7 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
             {
                 bool bFound = false;
                 for (SCSIZE i=0; i<nColCount && !bFound; i++)
-                    if ( mpColHeaders[i] == aTitle )
+                    if ( maColHeaders[i] == aTitle )
                     {
                         nPos = static_cast<SCCOL>(i);
                         bFound = true;
@@ -547,7 +533,7 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
             {
                 bool bFound = false;
                 for (SCSIZE i=0; i<nRowCount && !bFound; i++)
-                    if ( mpRowHeaders[i] == aTitle )
+                    if ( maRowHeaders[i] == aTitle )
                     {
                         nPos = static_cast<SCROW>(i);
                         bFound = true;
@@ -656,10 +642,10 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow,
 
     if (bColByName)
         for (SCSIZE i=0; i<nColCount; i++)
-            pDestDoc->SetString( sal::static_int_cast<SCCOL>(nStartCol+i), nRow, nTab, mpColHeaders[i] );
+            pDestDoc->SetString( sal::static_int_cast<SCCOL>(nStartCol+i), nRow, nTab, maColHeaders[i] );
     if (bRowByName)
         for (SCSIZE j=0; j<nRowCount; j++)
-            pDestDoc->SetString( nCol, sal::static_int_cast<SCROW>(nStartRow+j), nTab, mpRowHeaders[j] );
+            pDestDoc->SetString( nCol, sal::static_int_cast<SCROW>(nStartRow+j), nTab, maRowHeaders[j] );
 
     nCol = nStartCol;
     nRow = nStartRow;
@@ -769,7 +755,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow,
 
                 //  Zwischentitel
 
-                if (ppTitlePos && mpTitles && mpRowHeaders)
+                if (ppTitlePos && !maTitles.empty() && !maRowHeaders.empty())
                 {
                     OUString aDelim( " / " );
                     for (SCSIZE nPos=0; nPos<nDataCount; nPos++)
@@ -781,9 +767,9 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow,
                                 bDo = false;                                    // leer
                         if ( bDo && nTPos < nNeeded )
                         {
-                            aString =  mpRowHeaders[nArrY];
+                            aString =  maRowHeaders[nArrY];
                             aString += aDelim;
-                            aString += mpTitles[nPos];
+                            aString += maTitles[nPos];
                             pDestDoc->SetString( nCol-1, nRow+nArrY+nTPos, nTab, aString );
                         }
                     }


More information about the Libreoffice-commits mailing list