[Libreoffice-commits] .: Branch 'libreoffice-3-4' - sc/inc sc/source

Markus Mohrhard mmohrhard at kemper.freedesktop.org
Mon Sep 5 18:09:08 PDT 2011


 sc/inc/rangenam.hxx               |    7 +++++++
 sc/source/core/data/documen2.cxx  |    2 +-
 sc/source/core/data/document.cxx  |   10 +++-------
 sc/source/filter/excel/xiname.cxx |   15 +++++++++++----
 sc/source/filter/html/htmlimp.cxx |    3 +--
 sc/source/ui/app/inputwin.cxx     |    2 --
 sc/source/ui/docshell/docfunc.cxx |    1 -
 sc/source/ui/namedlg/namedlg.cxx  |    5 ++---
 sc/source/ui/unoobj/nameuno.cxx   |    4 ++--
 sc/source/ui/view/viewfunc.cxx    |    4 +---
 10 files changed, 28 insertions(+), 25 deletions(-)

New commits:
commit 3eea3945e2457667a4e16d93bd2dec4ffaa88011
Author: Eike Rathke <erack at erack.de>
Date:   Tue Sep 6 02:10:41 2011 +0200

    crash when modifing a named range
    
    Signed-off-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 86d33c6..fdff278 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -217,7 +217,14 @@ public:
     SC_DLLPUBLIC iterator end();
     SC_DLLPUBLIC size_t size() const;
     bool empty() const;
+
+    /** Insert object into set if not a duplicate.
+        @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
+        ownership of p and if it can't insert it deletes the object! So, if
+        this insert here returns false the object where p pointed to is gone!
+     */
     SC_DLLPUBLIC bool insert(ScRangeData* p);
+
     void erase(const ScRangeData& r);
 
     /**
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 80b0c12..97292ca 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -1015,7 +1015,7 @@ sal_uLong ScDocument::TransferTab( ScDocument* pSrcDoc, SCTAB nSrcPos,
                             if (!pRangeName->insert(pData))
                             {
                                 OSL_FAIL("can't insert name");     // shouldn't happen
-                                delete pData;
+                                pData = NULL;
                             }
                             else
                             {
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 3e86a75..6668b74 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -1719,9 +1719,7 @@ void ScDocument::TransposeClip( ScDocument* pTransClip, sal_uInt16 nFlags, sal_B
         {
             sal_uInt16 nIndex = itr->GetIndex();
             ScRangeData* pData = new ScRangeData(*itr);
-            if (!pTransClip->pRangeName->insert(pData))
-                delete pData;
-            else
+            if (pTransClip->pRangeName->insert(pData))
                 pData->SetIndex(nIndex);
         }
     }
@@ -1784,9 +1782,7 @@ void copyUsedNamesToClip(ScRangeName* pClipRangeName, ScRangeName* pRangeName, c
             continue;
 
         ScRangeData* pData = new ScRangeData(*itr);
-        if (!pClipRangeName->insert(pData))
-            delete pData;
-        else
+        if (pClipRangeName->insert(pData))
             pData->SetIndex(nIndex);
     }
 }
@@ -1894,7 +1890,7 @@ void ScDocument::CopyRangeNamesFromClip(ScDocument* pClipDoc, ScClipRangeNameDat
             }
             else
             {   // must be an overflow
-                delete pData;
+                pData = NULL;
                 aClipRangeNames.insert(itr->GetIndex(), 0);
                 aClipRangeNames.mbReplace = true;
             }
diff --git a/sc/source/filter/excel/xiname.cxx b/sc/source/filter/excel/xiname.cxx
index 8a80f52..938fb69 100644
--- a/sc/source/filter/excel/xiname.cxx
+++ b/sc/source/filter/excel/xiname.cxx
@@ -216,14 +216,20 @@ XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
         pData->GuessPosition();             // calculate base position for relative refs
         pData->SetIndex( nXclNameIdx );     // used as unique identifier in formulas
         if (nXclTab == EXC_NAME_GLOBAL)
-            GetDoc().GetRangeName()->insert(pData);
+        {
+            if (!GetDoc().GetRangeName()->insert(pData))
+                pData = NULL;
+        }
         else
         {
             ScRangeName* pLocalNames = GetDoc().GetRangeName(mnScTab);
             if (pLocalNames)
-                pLocalNames->insert(pData);
+            {
+                if (!pLocalNames->insert(pData))
+                    pData = NULL;
+            }
 
-            if (GetBiff() == EXC_BIFF8)
+            if (GetBiff() == EXC_BIFF8 && pData)
             {
                 ScRange aRange;
                 // discard deleted ranges ( for the moment at least )
@@ -233,7 +239,8 @@ XclImpName::XclImpName( XclImpStream& rStrm, sal_uInt16 nXclNameIdx ) :
                 }
             }
         }
-        mpScData = pData;                   // cache for later use
+        if (pData)
+            mpScData = pData;               // cache for later use
     }
 }
 
diff --git a/sc/source/filter/html/htmlimp.cxx b/sc/source/filter/html/htmlimp.cxx
index b8a5575..7ebe5e1 100644
--- a/sc/source/filter/html/htmlimp.cxx
+++ b/sc/source/filter/html/htmlimp.cxx
@@ -132,8 +132,7 @@ void ScHTMLImport::InsertRangeName( ScDocument* pDoc, const String& rName, const
     ScTokenArray aTokArray;
     aTokArray.AddDoubleReference( aRefData );
     ScRangeData* pRangeData = new ScRangeData( pDoc, rName, aTokArray );
-    if( !pDoc->GetRangeName()->insert( pRangeData ) )
-        delete pRangeData;
+    pDoc->GetRangeName()->insert( pRangeData );
 }
 
 void ScHTMLImport::WriteToDocument(
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 49c35a4..4f377ef 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1690,8 +1690,6 @@ void ScPosWnd::DoEnter()
                             aFunc.ModifyRangeNames( aNewRanges );
                             pViewSh->UpdateInputHandler(true);
                         }
-                        else
-                            delete pNew;        // shouldn't happen
                     }
                 }
                 else
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b752383..89d99b9 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -4610,7 +4610,6 @@ void ScDocFunc::CreateOneName( ScRangeName& rList,
                 if (!rList.insert(pData))
                 {
                     OSL_FAIL("nanu?");
-                    delete pData;
                 }
             }
         }
diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx
index 2452d83..157c316 100644
--- a/sc/source/ui/namedlg/namedlg.cxx
+++ b/sc/source/ui/namedlg/namedlg.cxx
@@ -388,8 +388,7 @@ bool ScNameDlg::AddPushed()
                 //	  in ein Token-Array uebersetzt werden?)
                 if ( 0 == pNewEntry->GetErrCode() )
                 {
-                    rtl::OUString aUpper = aNewEntry;
-                    aUpper.toAsciiUpperCase();
+                    rtl::OUString aUpper( ScGlobal::pCharClass->upper( aNewEntry ) );
                     ScRangeData* pData = mpCurRangeName->findByUpperName(aUpper);
                     if (pData)
                     {
@@ -400,7 +399,7 @@ bool ScNameDlg::AddPushed()
                         mpImpl->Clear();
 
                     if ( !mpCurRangeName->insert( pNewEntry ) )
-                        delete pNewEntry;
+                        pNewEntry = NULL;
 
                     UpdateNames();
                     bSaved=false;
diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx
index 52d9006..baae085 100644
--- a/sc/source/ui/unoobj/nameuno.cxx
+++ b/sc/source/ui/unoobj/nameuno.cxx
@@ -192,7 +192,7 @@ void ScNamedRangeObj::Modify_Impl( const String* pNewName, const ScTokenArray* p
     }
     else
     {
-        delete pNew;		//! uno::Exception/Fehler oder so
+        pNew = NULL;
         delete pNewRanges;
     }
 }
@@ -577,7 +577,7 @@ void SAL_CALL ScNamedRangesObj::addNewByName( const rtl::OUString& aName,
             }
             else
             {
-                delete pNew;
+                pNew = NULL;
                 delete pNewRanges;
             }
         }
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index 85f7b06..9a8587c 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -2945,10 +2945,8 @@ sal_Bool ScViewFunc::InsertName( const String& rName, const String& rSymbol,
         }
 
         if ( pList->insert( pNewEntry ) )
-        {
-            pNewEntry = NULL;	// nicht loeschen
             bOk = sal_True;
-        }
+        pNewEntry = NULL; // never delete, insert took ownership
 
         pDoc->CompileNameFormula( false );	// CompileFormulaString
         aModificator.SetDocumentModified();


More information about the Libreoffice-commits mailing list