[Libreoffice-commits] core.git: compilerplugins/clang filter/source idlc/inc idlc/source registry/source sc/inc sc/source svgio/inc svgio/source sw/source vcl/inc vcl/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Jul 14 08:14:27 UTC 2017


 compilerplugins/clang/test/useuniqueptr.cxx |    9 ++++++---
 compilerplugins/clang/useuniqueptr.cxx      |   12 ++++++------
 filter/source/graphicfilter/itga/itga.cxx   |   26 ++++++++++----------------
 idlc/inc/astexpression.hxx                  |    5 +++--
 idlc/source/astexpression.cxx               |   21 ++++++++++-----------
 registry/source/reflwrit.cxx                |   25 ++++---------------------
 sc/inc/scmod.hxx                            |    8 +++++---
 sc/source/ui/app/scmod.cxx                  |    1 -
 sc/source/ui/inc/undoblk.hxx                |    6 ++++--
 sc/source/ui/inc/undotab.hxx                |    9 ++++++---
 sc/source/ui/undo/undoblk.cxx               |    8 +++-----
 sc/source/ui/undo/undotab.cxx               |    9 +++------
 svgio/inc/svgpatternnode.hxx                |   11 +++++++----
 svgio/source/svgreader/svgpatternnode.cxx   |    6 ++----
 sw/source/filter/html/htmlctxt.cxx          |   20 +++++++++++---------
 vcl/inc/window.h                            |   12 +++++++-----
 vcl/source/window/window.cxx                |    1 -
 vcl/source/window/winproc.cxx               |   22 +++++-----------------
 18 files changed, 92 insertions(+), 119 deletions(-)

New commits:
commit 8e39ef66928a3e37c618d3a70a631e71266db274
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jul 13 20:42:04 2017 +0200

    extend loplugin useuniqueptr to POD types
    
    Change-Id: I6ff24f048bd8f75bf87a78b718f37b57855d4781
    Reviewed-on: https://gerrit.libreoffice.org/39932
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx
index e834123264e0..7e64bcca8986 100644
--- a/compilerplugins/clang/test/useuniqueptr.cxx
+++ b/compilerplugins/clang/test/useuniqueptr.cxx
@@ -7,9 +7,12 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+struct XXX {
+    ~XXX() {}
+};
 
 class Foo1 {
-    char* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}}
+    XXX* m_pbar; // expected-note {{member is here [loplugin:useuniqueptr]}}
     ~Foo1()
     {
         delete m_pbar; // expected-error {{a destructor with only a single unconditional call to delete on a member, is a sure sign it should be using std::unique_ptr for that field [loplugin:useuniqueptr]}}
@@ -23,8 +26,8 @@ class Foo2 {
     char* m_pbar2; // expected-note {{member is here [loplugin:useuniqueptr]}}
     ~Foo2()
     {
-        delete[] m_pbar1; // expected-error {{managing array of trival type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}}
-        delete[] m_pbar2; // expected-error {{managing array of trival type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}}
+        delete[] m_pbar1; // expected-error {{managing POD type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}}
+        delete[] m_pbar2; // expected-error {{managing POD type 'char' manually, rather use std::vector / std::array / std::unique_ptr [loplugin:useuniqueptr]}}
     }
 };
 
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 9e0dd33e900b..dc1371f00b4a 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -37,7 +37,7 @@ public:
     bool VisitCompoundStmt(const CompoundStmt* );
 private:
     void CheckForSingleUnconditionalDelete(const CXXDestructorDecl*, const CompoundStmt* );
-    void CheckForDeleteArrayOfPOD(const CompoundStmt* );
+    void CheckForDeleteOfPOD(const CompoundStmt* );
 };
 
 bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDecl)
@@ -52,7 +52,7 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
         return true;
 
     CheckForSingleUnconditionalDelete(destructorDecl, compoundStmt);
-    CheckForDeleteArrayOfPOD(compoundStmt);
+    CheckForDeleteOfPOD(compoundStmt);
 
     return true;
 }
@@ -195,13 +195,13 @@ bool UseUniquePtr::VisitCompoundStmt(const CompoundStmt* compoundStmt)
     return true;
 }
 
-void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt)
+void UseUniquePtr::CheckForDeleteOfPOD(const CompoundStmt* compoundStmt)
 {
     for (auto i = compoundStmt->body_begin();
               i != compoundStmt->body_end(); ++i)
     {
         auto deleteExpr = dyn_cast<CXXDeleteExpr>(*i);
-        if (!deleteExpr || !deleteExpr->isArrayForm())
+        if (!deleteExpr)
             continue;
 
         const Expr* argExpr = deleteExpr->getArgument();
@@ -221,7 +221,7 @@ void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt)
 
         auto pointerType = dyn_cast<PointerType>(fieldDecl->getType()->getUnqualifiedDesugaredType());
         QualType elementType = pointerType->getPointeeType();
-        if (!elementType.isTrivialType(compiler.getASTContext()))
+        if (!elementType.isPODType(compiler.getASTContext()))
             continue;
 
         StringRef aFileName = compiler.getSourceManager().getFilename(compiler.getSourceManager().getSpellingLoc(fieldDecl->getLocStart()));
@@ -237,7 +237,7 @@ void UseUniquePtr::CheckForDeleteArrayOfPOD(const CompoundStmt* compoundStmt)
 
         report(
             DiagnosticsEngine::Warning,
-            "managing array of trival type %0 manually, rather use std::vector / std::array / std::unique_ptr",
+            "managing POD type %0 manually, rather use std::vector / std::array / std::unique_ptr",
             deleteExpr->getLocStart())
             << elementType
             << deleteExpr->getSourceRange();
diff --git a/filter/source/graphicfilter/itga/itga.cxx b/filter/source/graphicfilter/itga/itga.cxx
index bb16e1000626..6eaafe722932 100644
--- a/filter/source/graphicfilter/itga/itga.cxx
+++ b/filter/source/graphicfilter/itga/itga.cxx
@@ -83,9 +83,12 @@ private:
     SvStream&           m_rTGA;
 
     BitmapWriteAccess*  mpAcc;
-    TGAFileHeader*      mpFileHeader;
-    TGAFileFooter*      mpFileFooter;
-    TGAExtension*       mpExtension;
+    std::unique_ptr<TGAFileHeader>
+                        mpFileHeader;
+    std::unique_ptr<TGAFileFooter>
+                        mpFileFooter;
+    std::unique_ptr<TGAExtension>
+                        mpExtension;
     std::unique_ptr<sal_uInt32[]>
                         mpColorMap;
 
@@ -102,7 +105,6 @@ private:
 
 public:
     explicit TGAReader(SvStream &rTGA);
-    ~TGAReader();
     bool                ReadTGA(Graphic &rGraphic);
 };
 
@@ -123,14 +125,6 @@ TGAReader::TGAReader(SvStream &rTGA)
 {
 }
 
-TGAReader::~TGAReader()
-{
-    delete mpFileHeader;
-    delete mpExtension;
-    delete mpFileFooter;
-}
-
-
 bool TGAReader::ReadTGA(Graphic & rGraphic)
 {
     if ( m_rTGA.GetError() )
@@ -175,7 +169,7 @@ bool TGAReader::ReadTGA(Graphic & rGraphic)
 
 bool TGAReader::ImplReadHeader()
 {
-    mpFileHeader = new TGAFileHeader;
+    mpFileHeader.reset( new TGAFileHeader );
 
     m_rTGA.ReadUChar( mpFileHeader->nImageIDLength ).ReadUChar( mpFileHeader->nColorMapType ).ReadUChar( mpFileHeader->nImageType ).        ReadUInt16( mpFileHeader->nColorMapFirstEntryIndex ).ReadUInt16( mpFileHeader->nColorMapLength ).ReadUChar( mpFileHeader->nColorMapEntrySize ).            ReadUInt16( mpFileHeader->nColorMapXOrigin ).ReadUInt16( mpFileHeader->nColorMapYOrigin ).ReadUInt16( mpFileHeader->nImageWidth ).                ReadUInt16( mpFileHeader->nImageHeight ).ReadUChar( mpFileHeader->nPixelDepth ).ReadUChar( mpFileHeader->nImageDescriptor );
 
@@ -188,8 +182,8 @@ bool TGAReader::ImplReadHeader()
         mbIndexing = true;
 
     // first we want to get the version
-    mpFileFooter = new TGAFileFooter;       // read the TGA-File-Footer to determine whether
-                                            // we got an old TGA format or the new one
+    mpFileFooter.reset( new TGAFileFooter );  // read the TGA-File-Footer to determine whether
+                                              // we got an old TGA format or the new one
 
     sal_uLong nCurStreamPos = m_rTGA.Tell();
     m_rTGA.Seek( STREAM_SEEK_TO_END );
@@ -208,7 +202,7 @@ bool TGAReader::ImplReadHeader()
          mpFileFooter->nSignature[ 2 ] == (('O'<<24)|('N'<<16)|('-'<<8)|'X') &&
          mpFileFooter->nSignature[ 3 ] == (('F'<<24)|('I'<<16)|('L'<<8)|'E') )
     {
-        mpExtension = new TGAExtension;
+        mpExtension.reset( new TGAExtension );
 
         m_rTGA.Seek( mpFileFooter->nExtensionFileOffset );
         m_rTGA.ReadUInt16( mpExtension->nExtensionSize );
diff --git a/idlc/inc/astexpression.hxx b/idlc/inc/astexpression.hxx
index 955ffa49a233..eec117379b6f 100644
--- a/idlc/inc/astexpression.hxx
+++ b/idlc/inc/astexpression.hxx
@@ -103,7 +103,7 @@ public:
 
     // Data Accessors
     AstExprValue* getExprValue()
-        { return m_exprValue; }
+        { return m_exprValue.get(); }
 
     // Evaluation and value coercion
     bool coerce(ExprType type);
@@ -129,7 +129,8 @@ private:
     ExprComb        m_combOperator;
     AstExpression*  m_subExpr1;
     AstExpression*  m_subExpr2;
-    AstExprValue*   m_exprValue;
+    std::unique_ptr<AstExprValue>
+                    m_exprValue;
     OString* m_pSymbolicName;
 };
 
diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx
index 8615c7962f7e..0840ccf756d9 100644
--- a/idlc/source/astexpression.cxx
+++ b/idlc/source/astexpression.cxx
@@ -49,7 +49,7 @@ AstExpression::AstExpression(sal_Int32 l)
 {
     fillDefinitionDetails();
 
-    m_exprValue = new AstExprValue;
+    m_exprValue.reset( new AstExprValue );
     m_exprValue->et = ET_long;
     m_exprValue->u.lval = l;
 }
@@ -63,7 +63,7 @@ AstExpression::AstExpression(sal_Int32  l, ExprType et)
 {
     fillDefinitionDetails();
 
-    m_exprValue = new AstExprValue;
+    m_exprValue.reset( new AstExprValue );
     m_exprValue->et = et;
     m_exprValue->u.lval = l;
 }
@@ -77,7 +77,7 @@ AstExpression::AstExpression(sal_Int64  h)
 {
     fillDefinitionDetails();
 
-    m_exprValue = new AstExprValue;
+    m_exprValue.reset( new AstExprValue );
     m_exprValue->et = ET_hyper;
     m_exprValue->u.hval = h;
 }
@@ -91,7 +91,7 @@ AstExpression::AstExpression(sal_uInt64 uh)
 {
     fillDefinitionDetails();
 
-    m_exprValue = new AstExprValue;
+    m_exprValue.reset( new AstExprValue );
     m_exprValue->et = ET_uhyper;
     m_exprValue->u.uhval = uh;
 }
@@ -105,7 +105,7 @@ AstExpression::AstExpression(double d)
 {
     fillDefinitionDetails();
 
-    m_exprValue = new AstExprValue;
+    m_exprValue.reset( new AstExprValue );
     m_exprValue->et = ET_double;
     m_exprValue->u.dval = d;
 }
@@ -122,7 +122,6 @@ AstExpression::AstExpression(OString* scopedName)
 
 AstExpression::~AstExpression()
 {
-    delete m_exprValue;
     delete m_subExpr1;
     delete m_subExpr2;
     delete m_pSymbolicName;
@@ -753,7 +752,7 @@ bool AstExpression::coerce(ExprType t)
         copy = nullptr;
     }
 
-    m_exprValue = copy;
+    m_exprValue.reset( copy );
 
     return m_exprValue != nullptr;
 }
@@ -804,21 +803,21 @@ void AstExpression::evaluate()
         case ExprComb::Mul:
         case ExprComb::Div:
         case ExprComb::Mod:
-            m_exprValue = eval_bin_op().release();
+            m_exprValue = eval_bin_op();
             break;
         case ExprComb::Or:
         case ExprComb::Xor:
         case ExprComb::And:
         case ExprComb::Left:
         case ExprComb::Right:
-            m_exprValue = eval_bit_op().release();
+            m_exprValue = eval_bit_op();
             break;
         case ExprComb::UPlus:
         case ExprComb::UMinus:
-            m_exprValue = eval_un_op().release();
+            m_exprValue = eval_un_op();
             break;
         case ExprComb::Symbol:
-            m_exprValue = eval_symbol();
+            m_exprValue.reset( eval_symbol() );
             break;
         case ExprComb::NONE:
             break;
diff --git a/registry/source/reflwrit.cxx b/registry/source/reflwrit.cxx
index 747855850632..6432ac4290a4 100644
--- a/registry/source/reflwrit.cxx
+++ b/registry/source/reflwrit.cxx
@@ -622,8 +622,8 @@ public:
     RTTypeClass         m_typeClass;
     OString             m_typeName;
     sal_uInt16          m_nSuperTypes;
-    OString*            m_superTypeNames;
-    RTUik*              m_pUik;
+    std::unique_ptr<OString[]>
+                        m_superTypeNames;
     OString             m_doku;
     OString             m_fileName;
     sal_uInt16          m_fieldCount;
@@ -671,7 +671,6 @@ TypeWriter::TypeWriter(typereg_Version version,
             RTTypeClass | (published ? RT_TYPE_PUBLISHED : 0)))
      , m_typeName(typeName)
     , m_nSuperTypes(superTypeCount)
-    , m_pUik(nullptr)
     , m_doku(documentation)
     , m_fileName(fileName)
     , m_fieldCount(fieldCount)
@@ -684,10 +683,7 @@ TypeWriter::TypeWriter(typereg_Version version,
 {
     if (m_nSuperTypes > 0)
     {
-        m_superTypeNames = new OString[m_nSuperTypes];
-    } else
-    {
-        m_superTypeNames = nullptr;
+        m_superTypeNames.reset( new OString[m_nSuperTypes] );
     }
 
     if (m_fieldCount)
@@ -702,8 +698,6 @@ TypeWriter::TypeWriter(typereg_Version version,
 
 TypeWriter::~TypeWriter()
 {
-    delete[] m_superTypeNames;
-
     if (m_fieldCount)
         delete[] m_fields;
 
@@ -712,8 +706,6 @@ TypeWriter::~TypeWriter()
 
     if (m_referenceCount)
         delete[] m_references;
-
-    delete m_pUik;
 }
 
 void TypeWriter::setSuperType(sal_uInt16 index, OString const & name)
@@ -736,7 +728,6 @@ void TypeWriter::createBlop()
     CPInfo  root(CP_TAG_INVALID, nullptr);
     sal_uInt16  cpIndexThisName = 0;
     sal_uInt16* cpIndexSuperNames = nullptr;
-    sal_uInt16  cpIndexUik = 0;
     sal_uInt16  cpIndexDoku = 0;
     sal_uInt16  cpIndexFileName = 0;
     CPInfo* pInfo = nullptr;
@@ -773,14 +764,6 @@ void TypeWriter::createBlop()
         }
     }
 
-    // create CP entry for uik
-    if (m_pUik != nullptr)
-    {
-        pInfo = new CPInfo(CP_TAG_UIK, pInfo);
-        pInfo->m_value.aUik = m_pUik;
-        cpIndexUik = pInfo->m_index;
-    }
-
     // create CP entry for doku
     if (!m_doku.isEmpty())
     {
@@ -1064,7 +1047,7 @@ void TypeWriter::createBlop()
     pBuffer += writeUINT16(pBuffer, (sal_uInt16)RT_UNO_IDL);
     pBuffer += writeUINT16(pBuffer, (sal_uInt16)m_typeClass);
     pBuffer += writeUINT16(pBuffer, cpIndexThisName);
-    pBuffer += writeUINT16(pBuffer, cpIndexUik);
+    pBuffer += writeUINT16(pBuffer, 0); // cpIndexUik
     pBuffer += writeUINT16(pBuffer, cpIndexDoku);
     pBuffer += writeUINT16(pBuffer, cpIndexFileName);
 
diff --git a/sc/inc/scmod.hxx b/sc/inc/scmod.hxx
index 6f24143fc2af..3a85539dbe69 100644
--- a/sc/inc/scmod.hxx
+++ b/sc/inc/scmod.hxx
@@ -29,9 +29,10 @@
 #include "shellids.hxx"
 #include <unotools/options.hxx>
 
-#include <map>
-#include <list>
 #include <algorithm>
+#include <list>
+#include <map>
+#include <memory>
 #include <stack>
 
 class KeyEvent;
@@ -78,7 +79,8 @@ class ScModule: public SfxModule, public SfxListener, public utl::ConfigurationL
     Timer               aIdleTimer;
     Idle                aSpellIdle;
     ScDragData*         mpDragData;
-    ScClipData*         mpClipData;
+    std::unique_ptr<ScClipData>
+                        mpClipData;
     ScSelectionTransferObj* pSelTransfer;
     ScMessagePool*      pMessagePool;
     // there is no global InputHandler anymore, each View has it's own
diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx
index b5b314f4df20..e14cf65c7cf7 100644
--- a/sc/source/ui/app/scmod.cxx
+++ b/sc/source/ui/app/scmod.cxx
@@ -207,7 +207,6 @@ ScModule::~ScModule()
     DELETEZ( pFormEditData );
 
     delete mpDragData;
-    delete mpClipData;
     delete pErrorHdl;
 
     ScGlobal::Clear(); // Also calls ScDocumentPool::DeleteVersionMaps();
diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx
index 9b89e55a2fde..dca1045ee5a0 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -905,8 +905,10 @@ public:
 
 private:
     ScMarkData      aMarkData;
-    ScDocument*     pUndoDoc;
-    sal_uInt16*         pWhich;
+    std::unique_ptr<ScDocument>
+                    pUndoDoc;
+    std::unique_ptr<sal_uInt16[]>
+                    pWhich;
 };
 
 class ScUndoRemoveBreaks: public ScSimpleUndo
diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx
index 5585e2d3e9b8..477ac208a969 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -296,9 +296,12 @@ private:
     OUString    aOptions;
     sal_uLong   nRefreshDelay;
     sal_uInt16  nCount;
-    SCTAB*      pTabs;
-    ScLinkMode* pModes;
-    OUString*   pTabNames;
+    std::unique_ptr<SCTAB[]>
+                pTabs;
+    std::unique_ptr<ScLinkMode[]>
+                pModes;
+    std::unique_ptr<OUString[]>
+                pTabNames;
 
     void DoChange( bool bLink ) const;
 };
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 4696623ead07..f4ad5170139a 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -2042,15 +2042,13 @@ ScUndoClearItems::ScUndoClearItems( ScDocShell* pNewDocShell, const ScMarkData&
     sal_uInt16 nCount = 0;
     while ( pW[nCount] )
         ++nCount;
-    pWhich = new sal_uInt16[nCount+1];
+    pWhich.reset( new sal_uInt16[nCount+1] );
     for (sal_uInt16 i=0; i<=nCount; i++)
         pWhich[i] = pW[i];
 }
 
 ScUndoClearItems::~ScUndoClearItems()
 {
-    delete pUndoDoc;
-    delete pWhich;
 }
 
 OUString ScUndoClearItems::GetComment() const
@@ -2074,7 +2072,7 @@ void ScUndoClearItems::Redo()
     BeginRedo();
 
     ScDocument& rDoc = pDocShell->GetDocument();
-    rDoc.ClearSelectionItems( pWhich, aMarkData );
+    rDoc.ClearSelectionItems( pWhich.get(), aMarkData );
     pDocShell->PostPaint( aBlockRange, PaintPartFlags::Grid, SC_PF_LINES | SC_PF_TESTMERGE );
 
     EndRedo();
@@ -2085,7 +2083,7 @@ void ScUndoClearItems::Repeat(SfxRepeatTarget& rTarget)
     if (dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr)
     {
         ScViewData& rViewData = static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData();
-        rViewData.GetDocFunc().ClearItems( rViewData.GetMarkData(), pWhich, false );
+        rViewData.GetDocFunc().ClearItems( rViewData.GetMarkData(), pWhich.get(), false );
     }
 }
 
diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 67d7eee929b1..f3dc9aa6fe5d 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -1018,9 +1018,9 @@ ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const OUString& rDocName
 {
     ScDocument& rDoc = pDocShell->GetDocument();
     SCTAB nTabCount = rDoc.GetTableCount();
-    pTabs     = new SCTAB[nTabCount];
-    pModes    = new ScLinkMode[nTabCount];
-    pTabNames = new OUString[nTabCount];
+    pTabs.reset( new SCTAB[nTabCount] );
+    pModes.reset( new ScLinkMode[nTabCount] );
+    pTabNames.reset( new OUString[nTabCount] );
 
     for (SCTAB i=0; i<nTabCount; i++)
     {
@@ -1050,9 +1050,6 @@ ScUndoRemoveLink::ScUndoRemoveLink( ScDocShell* pShell, const OUString& rDocName
 
 ScUndoRemoveLink::~ScUndoRemoveLink()
 {
-    delete pTabs;
-    delete pModes;
-    delete[] pTabNames;
 }
 
 OUString ScUndoRemoveLink::GetComment() const
diff --git a/svgio/inc/svgpatternnode.hxx b/svgio/inc/svgpatternnode.hxx
index 73d3c126bcf2..f22439eae86a 100644
--- a/svgio/inc/svgpatternnode.hxx
+++ b/svgio/inc/svgpatternnode.hxx
@@ -22,6 +22,7 @@
 
 #include <svgnode.hxx>
 #include <svgstyleattributes.hxx>
+#include <memory>
 
 namespace svgio
 {
@@ -43,8 +44,10 @@ namespace svgio
             SvgNumber               maY;
             SvgNumber               maWidth;
             SvgNumber               maHeight;
-            SvgUnits*               mpPatternUnits;
-            SvgUnits*               mpPatternContentUnits;
+            std::unique_ptr<SvgUnits>
+                                    mpPatternUnits;
+            std::unique_ptr<SvgUnits>
+                                    mpPatternContentUnits;
             basegfx::B2DHomMatrix*  mpaPatternTransform;
 
             /// link to another pattern used as style. If maXLink
@@ -95,11 +98,11 @@ namespace svgio
 
             /// PatternUnits content
             const SvgUnits* getPatternUnits() const;
-            void setPatternUnits(const SvgUnits aPatternUnits) { if(mpPatternUnits) delete mpPatternUnits; mpPatternUnits = nullptr; mpPatternUnits = new SvgUnits(aPatternUnits); }
+            void setPatternUnits(const SvgUnits aPatternUnits) { mpPatternUnits.reset( new SvgUnits(aPatternUnits) ); }
 
             /// PatternContentUnits content
             const SvgUnits* getPatternContentUnits() const;
-            void setPatternContentUnits(const SvgUnits aPatternContentUnits) { if(mpPatternContentUnits) delete mpPatternContentUnits; mpPatternContentUnits = nullptr; mpPatternContentUnits = new SvgUnits(aPatternContentUnits); }
+            void setPatternContentUnits(const SvgUnits aPatternContentUnits) { mpPatternContentUnits.reset( new SvgUnits(aPatternContentUnits) ); }
 
             /// PatternTransform content
             const basegfx::B2DHomMatrix* getPatternTransform() const;
diff --git a/svgio/source/svgreader/svgpatternnode.cxx b/svgio/source/svgreader/svgpatternnode.cxx
index 44cd3850aca9..6fddc16af0c2 100644
--- a/svgio/source/svgreader/svgpatternnode.cxx
+++ b/svgio/source/svgreader/svgpatternnode.cxx
@@ -56,8 +56,6 @@ namespace svgio
         {
             delete mpViewBox;
             delete mpaPatternTransform;
-            delete mpPatternUnits;
-            delete mpPatternContentUnits;
         }
 
         const SvgStyleAttributes* SvgPatternNode::getSvgStyleAttributes() const
@@ -402,7 +400,7 @@ namespace svgio
         {
             if(mpPatternUnits)
             {
-                return mpPatternUnits;
+                return mpPatternUnits.get();
             }
 
             const_cast< SvgPatternNode* >(this)->tryToFindLink();
@@ -419,7 +417,7 @@ namespace svgio
         {
             if(mpPatternContentUnits)
             {
-                return mpPatternContentUnits;
+                return mpPatternContentUnits.get();
             }
 
             const_cast< SvgPatternNode* >(this)->tryToFindLink();
diff --git a/sw/source/filter/html/htmlctxt.cxx b/sw/source/filter/html/htmlctxt.cxx
index 0646803f9c92..4e67462f6ade 100644
--- a/sw/source/filter/html/htmlctxt.cxx
+++ b/sw/source/filter/html/htmlctxt.cxx
@@ -37,13 +37,17 @@
 #include "swcss1.hxx"
 #include "swhtml.hxx"
 
+#include <memory>
+
 using namespace ::com::sun::star;
 
 class HTMLAttrContext_SaveDoc
 {
     SwHTMLNumRuleInfo aNumRuleInfo; // Numbering for this environment
-    SwPosition  *pPos;              // Jump back to here when leaving context
-    HTMLAttrTable *pAttrTab;        // Valid attributes for the environment,
+    std::unique_ptr<SwPosition>
+                      pPos;         // Jump back to here when leaving context
+    std::unique_ptr<HTMLAttrTable>
+                      pAttrTab;     // Valid attributes for the environment,
                                     // if attributes shouldn't be preserved
 
     size_t nContextStMin;           // Stack lower bound for the environment
@@ -64,11 +68,9 @@ public:
         bFixHeaderDist( false ), bFixFooterDist( false )
     {}
 
-    ~HTMLAttrContext_SaveDoc() { delete pPos; delete pAttrTab; }
-
     // The position is ours, so we need to create and delete it
-    void SetPos( const SwPosition& rPos ) { pPos = new SwPosition(rPos); }
-    const SwPosition *GetPos() const { return pPos; }
+    void SetPos( const SwPosition& rPos ) { pPos.reset( new SwPosition(rPos) ); }
+    const SwPosition *GetPos() const { return pPos.get(); }
 
     // The index isn't ours. So no creation or deletion
     void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
@@ -99,10 +101,10 @@ HTMLAttrTable *HTMLAttrContext_SaveDoc::GetAttrTab( bool bCreate )
 {
     if( !pAttrTab && bCreate )
     {
-        pAttrTab = new HTMLAttrTable;
-        memset( pAttrTab, 0, sizeof( HTMLAttrTable ));
+        pAttrTab.reset( new HTMLAttrTable );
+        memset( pAttrTab.get(), 0, sizeof( HTMLAttrTable ));
     }
-    return pAttrTab;
+    return pAttrTab.get();
 }
 
 HTMLAttrContext_SaveDoc *HTMLAttrContext::GetSaveDocContext( bool bCreate )
diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index c55f650b6e2b..b305aa865515 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -27,6 +27,7 @@
 #include <o3tl/typed_flags_set.hxx>
 
 #include <list>
+#include <memory>
 #include <vector>
 #include <set>
 
@@ -84,14 +85,15 @@ bool ImplWindowFrameProc( vcl::Window* pInst, SalEvent nEvent, const void* pEven
 struct ImplWinData
 {
     OUString*           mpExtOldText;
-    ExtTextInputAttr*   mpExtOldAttrAry;
-    tools::Rectangle*          mpCursorRect;
+    std::unique_ptr<ExtTextInputAttr[]>
+                        mpExtOldAttrAry;
+    tools::Rectangle*   mpCursorRect;
     long                mnCursorExtWidth;
     bool                mbVertical;
-    tools::Rectangle*          mpCompositionCharRects;
+    tools::Rectangle*   mpCompositionCharRects;
     long                mnCompositionCharRects;
-    tools::Rectangle*          mpFocusRect;
-    tools::Rectangle*          mpTrackRect;
+    tools::Rectangle*   mpFocusRect;
+    tools::Rectangle*   mpTrackRect;
     ShowTrackFlags      mnTrackFlags;
     sal_uInt16          mnIsTopWindow;
     bool                mbMouseOver;            //< tracks mouse over for native widget paint effect
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 8ce275cef20a..cdcffdace4f8 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -766,7 +766,6 @@ ImplWinData::ImplWinData() :
 ImplWinData::~ImplWinData()
 {
     delete mpExtOldText;
-    delete mpExtOldAttrAry;
     delete mpCursorRect;
     delete[] mpCompositionCharRects;
     delete mpFocusRect;
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index 9cfb68742127..e7621bb58a40 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -1140,11 +1140,7 @@ static bool ImplHandleExtTextInput( vcl::Window* pWindow,
     {
         pChild->ImplGetWindowImpl()->mbExtTextInput = true;
         pWinData->mpExtOldText = new OUString;
-        if ( pWinData->mpExtOldAttrAry )
-        {
-            delete [] pWinData->mpExtOldAttrAry;
-            pWinData->mpExtOldAttrAry = nullptr;
-        }
+        pWinData->mpExtOldAttrAry.reset();
         pSVData->maWinData.mpExtTextInputWin = pChild;
         ImplCallCommand( pChild, CommandEventId::StartExtTextInput );
     }
@@ -1190,15 +1186,11 @@ static bool ImplHandleExtTextInput( vcl::Window* pWindow,
                                    nCursorPos, nCursorFlags,
                                    bOnlyCursor );
     *pWinData->mpExtOldText = rText;
-    if ( pWinData->mpExtOldAttrAry )
-    {
-        delete [] pWinData->mpExtOldAttrAry;
-        pWinData->mpExtOldAttrAry = nullptr;
-    }
+    pWinData->mpExtOldAttrAry.reset();
     if ( pTextAttr )
     {
-        pWinData->mpExtOldAttrAry = new ExtTextInputAttr[rText.getLength()];
-        memcpy( pWinData->mpExtOldAttrAry, pTextAttr, rText.getLength()*sizeof( ExtTextInputAttr ) );
+        pWinData->mpExtOldAttrAry.reset( new ExtTextInputAttr[rText.getLength()] );
+        memcpy( pWinData->mpExtOldAttrAry.get(), pTextAttr, rText.getLength()*sizeof( ExtTextInputAttr ) );
     }
     return !ImplCallCommand( pChild, CommandEventId::ExtTextInput, &aData );
 }
@@ -1219,11 +1211,7 @@ static bool ImplHandleEndExtTextInput()
             delete pWinData->mpExtOldText;
             pWinData->mpExtOldText = nullptr;
         }
-        if ( pWinData->mpExtOldAttrAry )
-        {
-            delete [] pWinData->mpExtOldAttrAry;
-            pWinData->mpExtOldAttrAry = nullptr;
-        }
+        pWinData->mpExtOldAttrAry.reset();
         bRet = !ImplCallCommand( pChild, CommandEventId::EndExtTextInput );
     }
 


More information about the Libreoffice-commits mailing list