diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-05-07 11:44:26 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-05-08 01:53:46 +0200 |
commit | 91b0d2122bdee361bf5412a42d48ff051159cbf2 (patch) | |
tree | 003ef60b93668847803a812486534ebc805e6546 /sd | |
parent | bdccb7e9991d83029eb2f2f11327b54534a00db8 (diff) |
tdf#116977 secured ::Clone methods
Renamed SdrPage::Clone -> SdrPage::CloneSdrPage
Renamed SdrObject::Clone -> SdrObject::CloneSdrObject
Giving SdrModel is no longer an option, but a must (as
reference). This makes future changes more safe by force
usage to think about it. Also equals the constructors
which already require a target SdrModel.
Done the same for ::CloneSdrPage.
Change-Id: I06f0129e15140bd8693db27a445037d7e2f7f652
Reviewed-on: https://gerrit.libreoffice.org/53933
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/sdpage.hxx | 2 | ||||
-rw-r--r-- | sd/source/core/drawdoc2.cxx | 4 | ||||
-rw-r--r-- | sd/source/core/drawdoc3.cxx | 4 | ||||
-rw-r--r-- | sd/source/core/sdpage2.cxx | 4 | ||||
-rw-r--r-- | sd/source/filter/ppt/pptin.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/animations/motionpathtag.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/dlg/animobjs.cxx | 22 | ||||
-rw-r--r-- | sd/source/ui/func/fumorph.cxx | 12 | ||||
-rw-r--r-- | sd/source/ui/func/fuvect.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/sidebar/DocumentHelper.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unoobj.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/view/GraphicObjectBar.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/drviews6.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/view/drviews9.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/sdview3.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/view/sdview4.cxx | 4 |
17 files changed, 54 insertions, 34 deletions
diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx index 5dedec0d3bb4..3e49c4f78e06 100644 --- a/sd/inc/sdpage.hxx +++ b/sd/inc/sdpage.hxx @@ -155,7 +155,7 @@ public: SdPage(SdDrawDocument& rNewDoc, bool bMasterPage); virtual ~SdPage() override; - virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const override; + virtual SdrPage* CloneSdrPage(SdrModel& rTargetModel) const override; virtual void SetSize(const Size& aSize) override; virtual void SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr) override; diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx index 13aa8af413c0..1a38fb080e99 100644 --- a/sd/source/core/drawdoc2.cxx +++ b/sd/source/core/drawdoc2.cxx @@ -1383,8 +1383,8 @@ sal_uInt16 SdDrawDocument::DuplicatePage ( } // Create duplicates of a standard page and the associated notes page - pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->Clone() ); - pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->Clone() ); + pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->CloneSdrPage(*this) ); + pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->CloneSdrPage(*this) ); return InsertPageSet ( pActualPage, diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx index e24a66466115..e598dc35e981 100644 --- a/sd/source/core/drawdoc3.cxx +++ b/sd/source/core/drawdoc3.cxx @@ -1488,8 +1488,8 @@ void SdDrawDocument::SetMasterPage(sal_uInt16 nSdPageNum, if (pSourceDoc != this) { // #i121863# clone masterpages, they are from another model (!) - SdPage* pNewNotesMaster = dynamic_cast< SdPage* >(pNotesMaster->Clone(this)); - SdPage* pNewMaster = dynamic_cast< SdPage* >(pMaster->Clone(this)); + SdPage* pNewNotesMaster = dynamic_cast< SdPage* >(pNotesMaster->CloneSdrPage(*this)); + SdPage* pNewMaster = dynamic_cast< SdPage* >(pMaster->CloneSdrPage(*this)); if(!pNewNotesMaster || !pNewMaster) { diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx index bb46eb4bc148..ee1f75059709 100644 --- a/sd/source/core/sdpage2.cxx +++ b/sd/source/core/sdpage2.cxx @@ -410,9 +410,9 @@ void SdPage::lateInit(const SdPage& rSrcPage) |* \************************************************************************/ -SdrPage* SdPage::Clone(SdrModel* pNewModel) const +SdrPage* SdPage::CloneSdrPage(SdrModel& rTargetModel) const { - SdDrawDocument& rSdDrawDocument(static_cast< SdDrawDocument& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel)); + SdDrawDocument& rSdDrawDocument(static_cast< SdDrawDocument& >(rTargetModel)); SdPage* pClonedSdPage( new SdPage( rSdDrawDocument, diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx index 056b2924a6ba..122262da6566 100644 --- a/sd/source/filter/ppt/pptin.cxx +++ b/sd/source/filter/ppt/pptin.cxx @@ -735,7 +735,7 @@ bool ImplSdPPTImport::Import() if ( pPersist->bStarDrawFiller && pPersist->bNotesMaster && ( nCurrentPageNum > 2 ) && ( ( nCurrentPageNum & 1 ) == 0 ) ) { pSdrModel->DeleteMasterPage( nCurrentPageNum ); - SdrPage* pNotesClone = static_cast<SdPage*>(pSdrModel->GetMasterPage( 2 ))->Clone(); + SdrPage* pNotesClone = static_cast<SdPage*>(pSdrModel->GetMasterPage( 2 ))->CloneSdrPage(*pSdrModel); pSdrModel->InsertMasterPage( pNotesClone, nCurrentPageNum ); if ( pNotesClone ) { diff --git a/sd/source/ui/animations/motionpathtag.cxx b/sd/source/ui/animations/motionpathtag.cxx index 6699ade88ff7..b5189251a276 100644 --- a/sd/source/ui/animations/motionpathtag.cxx +++ b/sd/source/ui/animations/motionpathtag.cxx @@ -986,10 +986,12 @@ void MotionPathTag::disposing() if( mpPathObj ) { - SdrPathObj* pPathObj = mpPathObj; + SdrObject* pTemp(mpPathObj); mpPathObj = nullptr; mrView.updateHandles(); - delete pPathObj; + + // always use SdrObject::Free(...) for SdrObjects (!) + SdrObject::Free(pTemp); } if( mpMark ) diff --git a/sd/source/ui/dlg/animobjs.cxx b/sd/source/ui/dlg/animobjs.cxx index 5ca6bab37ebd..8f48e7e13b29 100644 --- a/sd/source/ui/dlg/animobjs.cxx +++ b/sd/source/ui/dlg/animobjs.cxx @@ -789,7 +789,9 @@ void AnimationWindow::AddObj (::sd::View& rView ) ++m_nCurrentFrame; // Clone - pPage->InsertObject(pSnapShot->Clone(), m_nCurrentFrame); + pPage->InsertObject( + pSnapShot->CloneSdrObject(pPage->getSdrModelFromSdrPage()), + m_nCurrentFrame); } bAnimObj = true; } @@ -813,7 +815,7 @@ void AnimationWindow::AddObj (::sd::View& rView ) { SdrMark* pMark = rMarkList.GetMark(0); SdrObject* pObject = pMark->GetMarkedSdrObj(); - SdrObject* pClone = pObject->Clone(); + SdrObject* pClone(pObject->CloneSdrObject(pPage->getSdrModelFromSdrPage())); size_t nIndex = m_nCurrentFrame + 1; pPage->InsertObject(pClone, nIndex); } @@ -837,7 +839,9 @@ void AnimationWindow::AddObj (::sd::View& rView ) // increment => next one inserted after this one ++m_nCurrentFrame; - pPage->InsertObject(pObject->Clone(), m_nCurrentFrame); + pPage->InsertObject( + pObject->CloneSdrObject(pPage->getSdrModelFromSdrPage()), + m_nCurrentFrame); } bAnimObj = true; // that we don't change again } @@ -847,7 +851,11 @@ void AnimationWindow::AddObj (::sd::View& rView ) SdrObjList* pObjList = pCloneGroup->GetSubList(); for (size_t nObject= 0; nObject < nMarkCount; ++nObject) - pObjList->InsertObject(rMarkList.GetMark(nObject)->GetMarkedSdrObj()->Clone()); + { + pObjList->InsertObject( + rMarkList.GetMark(nObject)->GetMarkedSdrObj()->CloneSdrObject( + pPage->getSdrModelFromSdrPage())); + } size_t nIndex = m_nCurrentFrame + 1; pPage->InsertObject(pCloneGroup, nIndex); @@ -1074,7 +1082,7 @@ void AnimationWindow::CreateAnimObj (::sd::View& rView ) // the clone remains in the animation; we insert a clone of the // clone into the group pClone = pPage->GetObj(i); - SdrObject* pCloneOfClone = pClone->Clone(); + SdrObject* pCloneOfClone(pClone->CloneSdrObject(pPage->getSdrModelFromSdrPage())); //SdrObject* pCloneOfClone = pPage->GetObj(i)->Clone(); pObjList->InsertObject(pCloneOfClone); } @@ -1093,7 +1101,9 @@ void AnimationWindow::CreateAnimObj (::sd::View& rView ) // #i42894# if that worked, delete the group again if(!pGroup->GetSubList()->GetObjCount()) { - delete pGroup; + // always use SdrObject::Free(...) for SdrObjects (!) + SdrObject* pTemp(pGroup); + SdrObject::Free(pTemp); } } } diff --git a/sd/source/ui/func/fumorph.cxx b/sd/source/ui/func/fumorph.cxx index 2a2b2355b93f..6fa9494dfb7f 100644 --- a/sd/source/ui/func/fumorph.cxx +++ b/sd/source/ui/func/fumorph.cxx @@ -81,8 +81,8 @@ void FuMorph::DoExecute( SfxRequest& ) // create clones SdrObject* pObj1 = rMarkList.GetMark(0)->GetMarkedSdrObj(); SdrObject* pObj2 = rMarkList.GetMark(1)->GetMarkedSdrObj(); - SdrObject* pCloneObj1 = pObj1->Clone(); - SdrObject* pCloneObj2 = pObj2->Clone(); + SdrObject* pCloneObj1(pObj1->CloneSdrObject(pObj1->getSdrModelFromSdrObject())); + SdrObject* pCloneObj2(pObj2->CloneSdrObject(pObj2->getSdrModelFromSdrObject())); // delete text at clone, otherwise we do net get a correct PathObj pCloneObj1->SetOutlinerParaObject(nullptr); @@ -431,8 +431,12 @@ void FuMorph::ImpInsertPolygons( if ( nCount ) { - pObjList->InsertObject( pObj1->Clone(), 0 ); - pObjList->InsertObject( pObj2->Clone() ); + pObjList->InsertObject( + pObj1->CloneSdrObject(pObj1->getSdrModelFromSdrObject()), + 0 ); + pObjList->InsertObject( + pObj2->CloneSdrObject(pObj2->getSdrModelFromSdrObject()) ); + mpView->DeleteMarked(); mpView->InsertObjectAtView( pObjGroup, *pPageView, SdrInsertFlags:: SETDEFLAYER ); } diff --git a/sd/source/ui/func/fuvect.cxx b/sd/source/ui/func/fuvect.cxx index 6722e9e379c6..8a547243d6d8 100644 --- a/sd/source/ui/func/fuvect.cxx +++ b/sd/source/ui/func/fuvect.cxx @@ -70,7 +70,7 @@ void FuVectorize::DoExecute( SfxRequest& ) if( pPageView && rMtf.GetActionSize() ) { - SdrGrafObj* pVectObj = static_cast<SdrGrafObj*>( pObj->Clone() ); + SdrGrafObj* pVectObj = static_cast<SdrGrafObj*>( pObj->CloneSdrObject(pObj->getSdrModelFromSdrObject()) ); OUString aStr( mpView->GetDescriptionOfMarkedObjects() ); aStr += " " + SdResId( STR_UNDO_VECTORIZE ); mpView->BegUndo( aStr ); diff --git a/sd/source/ui/sidebar/DocumentHelper.cxx b/sd/source/ui/sidebar/DocumentHelper.cxx index b9336124f9e1..7198a19217d8 100644 --- a/sd/source/ui/sidebar/DocumentHelper.cxx +++ b/sd/source/ui/sidebar/DocumentHelper.cxx @@ -209,7 +209,7 @@ SdPage* DocumentHelper::AddMasterPage ( try { // Duplicate the master page. - pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone()); + pClonedMasterPage = static_cast<SdPage*>(pMasterPage->CloneSdrPage(rTargetDocument)); // Copy the necessary styles. SdDrawDocument& rSourceDocument(static_cast< SdDrawDocument& >(pMasterPage->getSdrModelFromSdrPage())); @@ -347,7 +347,7 @@ SdPage* DocumentHelper::AddMasterPage ( if (pMasterPage!=nullptr) { // Duplicate the master page. - pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone()); + pClonedMasterPage = static_cast<SdPage*>(pMasterPage->CloneSdrPage(rTargetDocument)); // Copy the precious flag. pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious()); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 677687e703d0..2c0c60302a02 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -505,7 +505,7 @@ SdPage* SdXImpressDocument::InsertSdPage( sal_uInt16 nPage, bool bDuplicate ) * standard page **************************************************************/ if( bDuplicate ) - pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->Clone() ); + pStandardPage = static_cast<SdPage*>( pPreviousStandardPage->CloneSdrPage(*mpDoc) ); else pStandardPage = mpDoc->AllocSdPage(false); @@ -540,7 +540,7 @@ SdPage* SdXImpressDocument::InsertSdPage( sal_uInt16 nPage, bool bDuplicate ) SdPage* pNotesPage = nullptr; if( bDuplicate ) - pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->Clone() ); + pNotesPage = static_cast<SdPage*>( pPreviousNotesPage->CloneSdrPage(*mpDoc) ); else pNotesPage = mpDoc->AllocSdPage(false); diff --git a/sd/source/ui/unoidl/unoobj.cxx b/sd/source/ui/unoidl/unoobj.cxx index 33e9928cafc5..5b0922b148a4 100644 --- a/sd/source/ui/unoidl/unoobj.cxx +++ b/sd/source/ui/unoidl/unoobj.cxx @@ -506,7 +506,10 @@ void SAL_CALL SdXShape::setPropertyValue( const OUString& aPropertyName, const c if(!pGroup->GetSubList()->GetObjCount()) { pPage->NbcRemoveObject(pGroup->GetOrdNum()); - delete pGroup; + + // always use SdrObject::Free(...) for SdrObjects (!) + SdrObject* pTemp(pGroup); + SdrObject::Free(pTemp); } } } diff --git a/sd/source/ui/view/GraphicObjectBar.cxx b/sd/source/ui/view/GraphicObjectBar.cxx index 90871e3e4456..acecdffd7dac 100644 --- a/sd/source/ui/view/GraphicObjectBar.cxx +++ b/sd/source/ui/view/GraphicObjectBar.cxx @@ -129,7 +129,7 @@ void GraphicObjectBar::ExecuteFilter( SfxRequest const & rReq ) if( pPageView ) { - SdrGrafObj* pFilteredObj = static_cast<SdrGrafObj*>( pObj->Clone() ); + SdrGrafObj* pFilteredObj = static_cast<SdrGrafObj*>( pObj->CloneSdrObject(pObj->getSdrModelFromSdrObject()) ); OUString aStr = mpView->GetDescriptionOfMarkedObjects(); aStr += " " + SdResId(STR_UNDO_GRAFFILTER); mpView->BegUndo( aStr ); diff --git a/sd/source/ui/view/drviews6.cxx b/sd/source/ui/view/drviews6.cxx index 595ec0353681..bfc0fe363e43 100644 --- a/sd/source/ui/view/drviews6.cxx +++ b/sd/source/ui/view/drviews6.cxx @@ -279,7 +279,8 @@ void DrawViewShell::ExecBmpMask( SfxRequest const & rReq ) if ( pObj && !mpDrawView->IsTextEdit() ) { - std::unique_ptr<SdrGrafObj> xNewObj(pObj->Clone()); + typedef std::unique_ptr< SdrGrafObj, SdrObjectFreeOp > SdrGrafObjPtr; + SdrGrafObjPtr xNewObj(pObj->CloneSdrObject(pObj->getSdrModelFromSdrObject())); bool bCont = true; if (xNewObj->IsLinkedGraphic()) diff --git a/sd/source/ui/view/drviews9.cxx b/sd/source/ui/view/drviews9.cxx index afc151b29a96..b253e25098ec 100644 --- a/sd/source/ui/view/drviews9.cxx +++ b/sd/source/ui/view/drviews9.cxx @@ -151,7 +151,7 @@ void DrawViewShell::ExecGallery(SfxRequest const & rReq) // the empty graphic object gets a new graphic bInsertNewObject = false; - SdrGrafObj* pNewGrafObj = pGrafObj->Clone(); + SdrGrafObj* pNewGrafObj(pGrafObj->CloneSdrObject(pGrafObj->getSdrModelFromSdrObject())); pNewGrafObj->SetEmptyPresObj(false); pNewGrafObj->SetOutlinerParaObject(nullptr); pNewGrafObj->SetGraphic(aGraphic); diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx index 73f06ae8f975..4100fe9dfacc 100644 --- a/sd/source/ui/view/sdview3.cxx +++ b/sd/source/ui/view/sdview3.cxx @@ -480,7 +480,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, for(size_t a = 0; a < pMarkList->GetMarkCount(); ++a) { SdrMark* pM = pMarkList->GetMark(a); - SdrObject* pObj = pM->GetMarkedSdrObj()->Clone(); + SdrObject* pObj(pM->GetMarkedSdrObj()->CloneSdrObject(pPage->getSdrModelFromSdrPage())); if(pObj) { @@ -714,7 +714,8 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( ( mnAction & DND_ACTION_MOVE ) && pPickObj2 && pObj ) { // replace object - SdrObject* pNewObj = pObj->Clone(); + SdrPage* pWorkPage = GetSdrPageView()->GetPage(); + SdrObject* pNewObj(pObj->CloneSdrObject(pWorkPage->getSdrModelFromSdrPage())); ::tools::Rectangle aPickObjRect( pPickObj2->GetCurrentBoundRect() ); Size aPickObjSize( aPickObjRect.GetSize() ); Point aVec( aPickObjRect.TopLeft() ); @@ -733,7 +734,6 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper, if( bUndo ) BegUndo(SdResId(STR_UNDO_DRAGDROP)); pNewObj->NbcSetLayer( pPickObj->GetLayer() ); - SdrPage* pWorkPage = GetSdrPageView()->GetPage(); pWorkPage->InsertObject( pNewObj ); if( bUndo ) { diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx index 0a8792cd8538..9d1cb05ed000 100644 --- a/sd/source/ui/view/sdview4.cxx +++ b/sd/source/ui/view/sdview4.cxx @@ -111,7 +111,7 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction, if( bIsGraphic ) { // We fill the object with the Bitmap - pNewGrafObj = static_cast<SdrGrafObj*>( pPickObj->Clone() ); + pNewGrafObj = static_cast<SdrGrafObj*>( pPickObj->CloneSdrObject(pPickObj->getSdrModelFromSdrObject()) ); pNewGrafObj->SetGraphic(rGraphic); } else @@ -318,7 +318,7 @@ SdrMediaObj* View::InsertMediaObj( const OUString& rMediaURL, const OUString& rM if( mnAction == DND_ACTION_LINK && pPickObj && pPV && dynamic_cast< SdrMediaObj *>( pPickObj ) != nullptr ) { - pNewMediaObj = static_cast< SdrMediaObj* >( pPickObj->Clone() ); + pNewMediaObj = static_cast< SdrMediaObj* >( pPickObj->CloneSdrObject(pPickObj->getSdrModelFromSdrObject()) ); pNewMediaObj->setURL( rMediaURL, ""/*TODO?*/, rMimeType ); BegUndo(SdResId(STR_UNDO_DRAGDROP)); |