[Libreoffice-commits] core.git: i18npool/source include/svl include/svtools include/tools io/source sot/source stoc/source svl/source svtools/source tools/source xmlhelp/source xmlscript/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Jun 27 06:42:59 UTC 2017


 i18npool/source/localedata/LocaleNode.cxx           |   24 +-----
 i18npool/source/localedata/LocaleNode.hxx           |    7 -
 i18npool/source/search/levdis.hxx                   |   13 +--
 include/svl/zformat.hxx                             |    5 -
 include/svtools/ctrltool.hxx                        |    3 
 include/tools/inetstrm.hxx                          |    3 
 io/source/TextInputStream/TextInputStream.cxx       |   43 +++--------
 sot/source/sdstor/stgio.cxx                         |    9 +-
 stoc/source/invocation_adapterfactory/iafactory.cxx |   31 +++-----
 svl/source/numbers/zformat.cxx                      |   77 ++++++++------------
 svtools/source/control/ctrltool.cxx                 |   18 +---
 tools/source/inet/inetstrm.cxx                      |   11 +-
 xmlhelp/source/cxxhelp/provider/databases.cxx       |   27 ++-----
 xmlhelp/source/cxxhelp/provider/databases.hxx       |    3 
 xmlscript/source/xml_helper/xml_impctx.cxx          |    3 
 15 files changed, 102 insertions(+), 175 deletions(-)

New commits:
commit 513ac8eb79e45de332d7ddab5b27c70578b904f1
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Jun 26 09:41:14 2017 +0200

    loplugin:useuniqueptr in various
    
    extending it to find places we can use std::unique_ptr on arrays
    
    Change-Id: I9feb1d12d738d6931e752ecb6dd51cbc1540c81b
    Reviewed-on: https://gerrit.libreoffice.org/39255
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/i18npool/source/localedata/LocaleNode.cxx b/i18npool/source/localedata/LocaleNode.cxx
index c1c5aaa81e32..8464775b2b2d 100644
--- a/i18npool/source/localedata/LocaleNode.cxx
+++ b/i18npool/source/localedata/LocaleNode.cxx
@@ -44,9 +44,6 @@ LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList >
     : aName(name)
     , aAttribs(attr)
     , parent(nullptr)
-    , children(nullptr)
-    , nChildren(0)
-    , childArrSize(0)
     , nError(0)
 {
 }
@@ -54,7 +51,7 @@ LocaleNode::LocaleNode (const OUString& name, const Reference< XAttributeList >
 int LocaleNode::getError() const
 {
     int err = nError;
-    for (sal_Int32 i=0;i<nChildren;i++)
+    for (size_t i=0;i<children.size();i++)
         err += children[i]->getError();
     return err;
 }
@@ -69,22 +66,14 @@ void LocaleNode::print () const {
 
 void LocaleNode::printR () const {
     print();
-    for (sal_Int32 i=0;i<nChildren;i++)
+    for (size_t i=0;i<children.size();i++)
         children[i]->printR();
     printf ("\t");
     print();
 }
 
 void LocaleNode::addChild ( LocaleNode * node) {
-    if (childArrSize <= nChildren) {
-        LocaleNode ** arrN = new LocaleNode*[childArrSize+10];
-        for (sal_Int32 i = 0; i<childArrSize; ++i)
-            arrN[i] = children[i];
-        delete [] children;
-        childArrSize += 10;
-        children = arrN;
-    }
-    children[nChildren++] = node;
+    children.push_back(node);
     node->parent = this;
 }
 
@@ -100,7 +89,7 @@ const LocaleNode* LocaleNode::getRoot() const
 const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
     if (aName.equalsAscii(name))
         return this;
-    for (sal_Int32 i = 0; i< nChildren; i++)  {
+    for (size_t i = 0; i< children.size(); i++)  {
         const LocaleNode *n=children[i]->findNode(name);
         if (n)
             return n;
@@ -110,9 +99,8 @@ const LocaleNode * LocaleNode::findNode ( const sal_Char *name) const {
 
 LocaleNode::~LocaleNode()
 {
-    for (sal_Int32 i=0; i < nChildren; ++i)
+    for (size_t i=0; i < children.size(); ++i)
         delete children[i];
-    delete [] children;
 }
 
 LocaleNode* LocaleNode::createNode (const OUString& name, const Reference< XAttributeList > & attr)
@@ -228,7 +216,7 @@ void LocaleNode::generateCode (const OFileWriter &of) const
         ++nError;
         fprintf( stderr, "Error: Locale versionDTD is not %s, see comment in locale.dtd\n", LOCALE_VERSION_DTD);
     }
-    for (sal_Int32 i=0; i<nChildren;i++)
+    for (size_t i=0; i<children.size(); i++)
         children[i]->generateCode (of);
 //      print_node( this );
 }
diff --git a/i18npool/source/localedata/LocaleNode.hxx b/i18npool/source/localedata/LocaleNode.hxx
index b64bdbb4ba0d..c3e6c57e6a22 100644
--- a/i18npool/source/localedata/LocaleNode.hxx
+++ b/i18npool/source/localedata/LocaleNode.hxx
@@ -18,6 +18,7 @@
  */
 #ifndef INCLUDED_I18NPOOL_SOURCE_LOCALEDATA_LOCALENODE_HXX
 #define INCLUDED_I18NPOOL_SOURCE_LOCALEDATA_LOCALENODE_HXX
+
 #include <com/sun/star/xml/sax/XParser.hpp>
 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
 
@@ -84,9 +85,7 @@ class LocaleNode
     OUString aValue;
     Attr aAttribs;
     LocaleNode * parent;
-    LocaleNode* * children;
-    sal_Int32 nChildren;
-    sal_Int32 childArrSize;
+    std::vector<LocaleNode*> children;
 
 protected:
     mutable int nError;
@@ -97,7 +96,7 @@ public:
     const OUString& getName() const { return aName; };
     const OUString& getValue() const { return aValue; };
     const Attr& getAttr() const { return aAttribs; };
-    sal_Int32 getNumberOfChildren () const { return nChildren; };
+    sal_Int32 getNumberOfChildren () const { return sal_Int32(children.size()); };
     LocaleNode * getChildAt (sal_Int32 idx) const { return children[idx] ; };
     const LocaleNode * findNode ( const sal_Char *name) const;
     void print () const;
diff --git a/i18npool/source/search/levdis.hxx b/i18npool/source/search/levdis.hxx
index daf8778806a3..1c4604ffd11e 100644
--- a/i18npool/source/search/levdis.hxx
+++ b/i18npool/source/search/levdis.hxx
@@ -96,8 +96,8 @@
 /** "Safe" memory allocation in ctor */
 class WLevDisPatternMem
 {
-    sal_Unicode     *cp;
-    bool            *bp;
+    std::unique_ptr<sal_Unicode[]> cp;
+    std::unique_ptr<bool[]>        bp;
 public:
     explicit WLevDisPatternMem( sal_Int32 s )
         : cp(new sal_Unicode[s])
@@ -105,13 +105,8 @@ public:
     {
     }
 
-    ~WLevDisPatternMem()
-    {
-        delete [] cp;
-        delete [] bp;
-    }
-    sal_Unicode* GetcPtr() const        { return cp; }
-    bool* GetbPtr() const               { return bp; }
+    sal_Unicode* GetcPtr() const        { return cp.get(); }
+    bool* GetbPtr() const               { return bp.get(); }
 };
 
 class WLevDisDistanceMem
diff --git a/include/svl/zformat.hxx b/include/svl/zformat.hxx
index e10060c04240..7e358d0c096a 100644
--- a/include/svl/zformat.hxx
+++ b/include/svl/zformat.hxx
@@ -23,6 +23,7 @@
 #include <i18nlangtag/mslangid.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/nfkeytab.hxx>
+#include <vector>
 
 namespace utl {
     class DigitGroupingIterator;
@@ -48,8 +49,8 @@ enum SvNumberformatLimitOps
 
 struct ImpSvNumberformatInfo            // Struct for FormatInfo
 {
-    OUString* sStrArray;                // Array of symbols
-    short* nTypeArray;                  // Array of infos
+    std::vector<OUString> sStrArray;    // Array of symbols
+    std::vector<short> nTypeArray;      // Array of infos
     sal_uInt16 nThousand;               // Count of group separator sequences
     sal_uInt16 nCntPre;                 // Count of digits before decimal point
     sal_uInt16 nCntPost;                // Count of digits after decimal point
diff --git a/include/svtools/ctrltool.hxx b/include/svtools/ctrltool.hxx
index 3b11eac75e36..4c642df4be47 100644
--- a/include/svtools/ctrltool.hxx
+++ b/include/svtools/ctrltool.hxx
@@ -144,7 +144,8 @@ private:
     OUString                maBoldItalic;
     OUString                maBlack;
     OUString                maBlackItalic;
-    sal_IntPtr*             mpSizeAry;
+    mutable std::unique_ptr<sal_IntPtr[]>
+                            mpSizeAry;
     VclPtr<OutputDevice>    mpDev;
     VclPtr<OutputDevice>    mpDev2;
     std::vector<std::unique_ptr<ImplFontListNameInfo>> m_Entries;
diff --git a/include/tools/inetstrm.hxx b/include/tools/inetstrm.hxx
index d09aa94fb4d3..ba6f6aa14744 100644
--- a/include/tools/inetstrm.hxx
+++ b/include/tools/inetstrm.hxx
@@ -22,6 +22,7 @@
 #include <tools/toolsdllapi.h>
 #include <tools/stream.hxx>
 #include <sal/types.h>
+#include <vector>
 
 class INetMIMEMessage;
 class SvStream;
@@ -31,7 +32,7 @@ class TOOLS_DLLPUBLIC INetMIMEMessageStream
     INetMIMEMessage *pSourceMsg;
     bool            bHeaderGenerated;
 
-    sal_Char       *pBuffer;
+    std::vector<sal_Char> mvBuffer;
     sal_Char       *pRead;
     sal_Char       *pWrite;
 
diff --git a/io/source/TextInputStream/TextInputStream.cxx b/io/source/TextInputStream/TextInputStream.cxx
index b49c5ec2e1c1..2beb825ed972 100644
--- a/io/source/TextInputStream/TextInputStream.cxx
+++ b/io/source/TextInputStream/TextInputStream.cxx
@@ -37,6 +37,8 @@
 
 #include "services.hxx"
 
+#include <vector>
+
 #define IMPLEMENTATION_NAME "com.sun.star.comp.io.TextInputStream"
 #define SERVICE_NAME "com.sun.star.io.TextInputStream"
 
@@ -67,12 +69,10 @@ class OTextInputStream : public WeakImplHelper< XTextInputStream2, XServiceInfo
     Sequence<sal_Int8>          mSeqSource;
 
     // Internal buffer for characters that are already converted successfully
-    sal_Unicode* mpBuffer;
-    sal_Int32 mnBufferSize;
+    std::vector<sal_Unicode> mvBuffer;
     sal_Int32 mnCharsInBuffer;
     bool mbReachedEOF;
 
-    void implResizeBuffer();
     /// @throws IOException
     /// @throws RuntimeException
     OUString implReadString( const Sequence< sal_Unicode >& Delimiters,
@@ -113,8 +113,7 @@ OTextInputStream::OTextInputStream()
     , mConvText2Unicode(nullptr)
     , mContextText2Unicode(nullptr)
     , mSeqSource(READ_BYTE_COUNT)
-    , mpBuffer(nullptr)
-    , mnBufferSize(0)
+    , mvBuffer(INITIAL_UNICODE_BUFFER_CAPACITY, 0)
     , mnCharsInBuffer(0)
     , mbReachedEOF(false)
 {
@@ -127,18 +126,6 @@ OTextInputStream::~OTextInputStream()
         rtl_destroyTextToUnicodeContext( mConvText2Unicode, mContextText2Unicode );
         rtl_destroyTextToUnicodeConverter( mConvText2Unicode );
     }
-
-    delete[] mpBuffer;
-}
-
-void OTextInputStream::implResizeBuffer()
-{
-    sal_Int32 nNewBufferSize = mnBufferSize * 2;
-    sal_Unicode* pNewBuffer = new sal_Unicode[ nNewBufferSize ];
-    memcpy( pNewBuffer, mpBuffer, mnCharsInBuffer * sizeof( sal_Unicode ) );
-    delete[] mpBuffer;
-    mpBuffer = pNewBuffer;
-    mnBufferSize = nNewBufferSize;
 }
 
 
@@ -175,12 +162,6 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
     if( !mbEncodingInitialized )
         return aRetStr;
 
-    if( !mpBuffer )
-    {
-        mnBufferSize = INITIAL_UNICODE_BUFFER_CAPACITY;
-        mpBuffer = new sal_Unicode[ mnBufferSize ];
-    }
-
     // Only for bFindLineEnd
     sal_Unicode cLineEndChar1 = 0x0D;
     sal_Unicode cLineEndChar2 = 0x0A;
@@ -208,7 +189,7 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
 
         // Now there should be characters available
         // (otherwise the loop should have been breaked before)
-        sal_Unicode c = mpBuffer[ nBufferReadPos++ ];
+        sal_Unicode c = mvBuffer[ nBufferReadPos++ ];
 
         if( bFindLineEnd )
         {
@@ -257,10 +238,10 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
 
     // Create string
     if( nCopyLen )
-        aRetStr = OUString( mpBuffer, nCopyLen );
+        aRetStr = OUString( mvBuffer.data(), nCopyLen );
 
     // Copy rest of buffer
-    memmove( mpBuffer, mpBuffer + nBufferReadPos,
+    memmove( mvBuffer.data(), mvBuffer.data() + nBufferReadPos,
         (mnCharsInBuffer - nBufferReadPos) * sizeof( sal_Unicode ) );
     mnCharsInBuffer -= nBufferReadPos;
 
@@ -270,10 +251,10 @@ OUString OTextInputStream::implReadString( const Sequence< sal_Unicode >& Delimi
 
 sal_Int32 OTextInputStream::implReadNext()
 {
-    sal_Int32 nFreeBufferSize = mnBufferSize - mnCharsInBuffer;
+    sal_Int32 nFreeBufferSize = mvBuffer.size() - mnCharsInBuffer;
     if( nFreeBufferSize < READ_BYTE_COUNT )
-        implResizeBuffer();
-    nFreeBufferSize = mnBufferSize - mnCharsInBuffer;
+        mvBuffer.resize(mvBuffer.size() * 2);
+    nFreeBufferSize = mvBuffer.size() - mnCharsInBuffer;
 
     try
     {
@@ -297,7 +278,7 @@ sal_Int32 OTextInputStream::implReadNext()
                                 mContextText2Unicode,
                                 reinterpret_cast<const char*>(&( pbSource[nSourceCount] )),
                                 nTotalRead - nSourceCount,
-                                mpBuffer + mnCharsInBuffer + nTargetCount,
+                                mvBuffer.data() + mnCharsInBuffer + nTargetCount,
                                 nFreeBufferSize - nTargetCount,
                                 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_DEFAULT   |
                                 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_DEFAULT |
@@ -309,7 +290,7 @@ sal_Int32 OTextInputStream::implReadNext()
             bool bCont = false;
             if( uiInfo & RTL_TEXTTOUNICODE_INFO_DESTBUFFERTOSMALL )
             {
-                implResizeBuffer();
+                mvBuffer.resize(mvBuffer.size() * 2);
                 bCont = true;
             }
 
diff --git a/sot/source/sdstor/stgio.cxx b/sot/source/sdstor/stgio.cxx
index 1ac21705ad03..a464ed1a06b9 100644
--- a/sot/source/sdstor/stgio.cxx
+++ b/sot/source/sdstor/stgio.cxx
@@ -145,14 +145,13 @@ bool StgIo::CommitAll()
 
 class EasyFat
 {
-    sal_Int32 *pFat;
-    bool  *pFree;
+    std::unique_ptr<sal_Int32[]> pFat;
+    std::unique_ptr<bool[]> pFree;
     sal_Int32 nPages;
     sal_Int32 nPageSize;
 
 public:
     EasyFat( StgIo & rIo, StgStrm *pFatStream, sal_Int32 nPSize );
-    ~EasyFat() { delete[] pFat; delete[] pFree; }
 
     sal_Int32 GetPageSize() { return nPageSize; }
 
@@ -164,8 +163,8 @@ EasyFat::EasyFat( StgIo& rIo, StgStrm* pFatStream, sal_Int32 nPSize )
 {
     nPages = pFatStream->GetSize() >> 2;
     nPageSize = nPSize;
-    pFat = new sal_Int32[ nPages ];
-    pFree = new bool[ nPages ];
+    pFat.reset( new sal_Int32[ nPages ] );
+    pFree.reset( new bool[ nPages ] );
 
     rtl::Reference< StgPage > pPage;
     sal_Int32 nFatPageSize = (1 << rIo.m_aHdr.GetPageSize()) - 2;
diff --git a/stoc/source/invocation_adapterfactory/iafactory.cxx b/stoc/source/invocation_adapterfactory/iafactory.cxx
index b7b3620a5d61..a4eba831991a 100644
--- a/stoc/source/invocation_adapterfactory/iafactory.cxx
+++ b/stoc/source/invocation_adapterfactory/iafactory.cxx
@@ -48,6 +48,7 @@
 
 #include <unordered_map>
 #include <unordered_set>
+#include <vector>
 
 #define IMPLNAME    "com.sun.star.comp.stoc.InvocationAdapterFactory"
 
@@ -130,8 +131,7 @@ struct AdapterImpl
     void *                      m_key; // map key
     uno_Interface *             m_pReceiver; // XInvocation receiver
 
-    sal_Int32                   m_nInterfaces;
-    InterfaceAdapterImpl *      m_pInterfaces;
+    std::vector<InterfaceAdapterImpl>  m_vInterfaces;
 
     // XInvocation calls
     void getValue(
@@ -166,12 +166,11 @@ struct AdapterImpl
 
 inline AdapterImpl::~AdapterImpl()
 {
-    for ( sal_Int32 nPos = m_nInterfaces; nPos--; )
+    for ( size_t nPos = m_vInterfaces.size(); nPos--; )
     {
         ::typelib_typedescription_release(
-            &m_pInterfaces[ nPos ].m_pTypeDescr->aBase );
+            &m_vInterfaces[ nPos ].m_pTypeDescr->aBase );
     }
-    delete [] m_pInterfaces;
 
     (*m_pReceiver->release)( m_pReceiver );
     m_pFactory->release();
@@ -577,15 +576,15 @@ static void SAL_CALL adapter_dispatch(
         typelib_TypeDescriptionReference * pDemanded =
             *static_cast<typelib_TypeDescriptionReference **>(pArgs[0]);
         // pInterfaces[0] is XInterface
-        for ( sal_Int32 nPos = 0; nPos < that->m_nInterfaces; ++nPos )
+        for ( size_t nPos = 0; nPos < that->m_vInterfaces.size(); ++nPos )
         {
             typelib_InterfaceTypeDescription * pTD =
-                that->m_pInterfaces[nPos].m_pTypeDescr;
+                that->m_vInterfaces[nPos].m_pTypeDescr;
             while (pTD)
             {
                 if (type_equals( pTD->aBase.pWeakRef, pDemanded ))
                 {
-                    uno_Interface * pUnoI2 = &that->m_pInterfaces[nPos];
+                    uno_Interface * pUnoI2 = &that->m_vInterfaces[nPos];
                     ::uno_any_construct(
                         static_cast<uno_Any *>(pReturn), &pUnoI2,
                         &pTD->aBase, nullptr );
@@ -632,15 +631,14 @@ AdapterImpl::AdapterImpl(
     FactoryImpl * pFactory )
         : m_nRef( 1 ),
           m_pFactory( pFactory ),
-          m_key( key )
+          m_key( key ),
+          m_vInterfaces( rTypes.getLength() )
 {
     // init adapters
-    m_nInterfaces = rTypes.getLength();
-    m_pInterfaces = new InterfaceAdapterImpl[ rTypes.getLength() ];
     const Type * pTypes = rTypes.getConstArray();
     for ( sal_Int32 nPos = rTypes.getLength(); nPos--; )
     {
-        InterfaceAdapterImpl * pInterface = &m_pInterfaces[nPos];
+        InterfaceAdapterImpl * pInterface = &m_vInterfaces[nPos];
         pInterface->acquire = adapter_acquire;
         pInterface->release = adapter_release;
         pInterface->pDispatcher = adapter_dispatch;
@@ -654,9 +652,8 @@ AdapterImpl::AdapterImpl(
             for ( sal_Int32 n = 0; n < nPos; ++n )
             {
                 ::typelib_typedescription_release(
-                    &m_pInterfaces[ n ].m_pTypeDescr->aBase );
+                    &m_vInterfaces[ n ].m_pTypeDescr->aBase );
             }
-            delete [] m_pInterfaces;
             throw RuntimeException(
                 "cannot retrieve all interface type infos!" );
         }
@@ -780,11 +777,11 @@ static inline AdapterImpl * lookup_adapter(
             Type const & rType = pTypes[ nPosTypes ];
             // find in adapter's type list
             sal_Int32 nPos;
-            for ( nPos = that->m_nInterfaces; nPos--; )
+            for ( nPos = that->m_vInterfaces.size(); nPos--; )
             {
                 if (::typelib_typedescriptionreference_isAssignableFrom(
                         rType.getTypeLibType(),
-                        that->m_pInterfaces[ nPos ].m_pTypeDescr->aBase.pWeakRef ))
+                        that->m_vInterfaces[ nPos ].m_pTypeDescr->aBase.pWeakRef ))
                 {
                     // found
                     break;
@@ -847,7 +844,7 @@ Reference< XInterface > FactoryImpl::createAdapter(
         }
         }
         // map one interface to C++
-        uno_Interface * pUnoI = &that->m_pInterfaces[ 0 ];
+        uno_Interface * pUnoI = &that->m_vInterfaces[ 0 ];
         m_aUno2Cpp.mapInterface(
             reinterpret_cast<void **>(&xRet), pUnoI, cppu::UnoType<decltype(xRet)>::get() );
         that->release();
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 6b06d6beed62..31073130b07b 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -269,8 +269,6 @@ sal_uInt8 SvNumberNatNum::MapNatNumToDBNum( sal_uInt8 nNatNum, LanguageType eLan
 ImpSvNumFor::ImpSvNumFor()
 {
     nAnzStrings = 0;
-    aI.nTypeArray = nullptr;
-    aI.sStrArray = nullptr;
     aI.eScannedType = css::util::NumberFormat::UNDEFINED;
     aI.bThousand = false;
     aI.nThousand = 0;
@@ -282,27 +280,15 @@ ImpSvNumFor::ImpSvNumFor()
 
 ImpSvNumFor::~ImpSvNumFor()
 {
-    delete [] aI.sStrArray;
-    delete [] aI.nTypeArray;
 }
 
 void ImpSvNumFor::Enlarge(sal_uInt16 nAnz)
 {
     if ( nAnzStrings != nAnz )
     {
-        delete [] aI.nTypeArray;
-        delete [] aI.sStrArray;
         nAnzStrings = nAnz;
-        if ( nAnz )
-        {
-            aI.nTypeArray = new short[nAnz];
-            aI.sStrArray  = new OUString[nAnz];
-        }
-        else
-        {
-            aI.nTypeArray = nullptr;
-            aI.sStrArray  = nullptr;
-        }
+        aI.nTypeArray.resize(nAnz);
+        aI.sStrArray.resize(nAnz);
     }
 }
 
@@ -3363,11 +3349,11 @@ bool SvNumberformat::ImpIsIso8601( const ImpSvNumFor& rNumFor ) const
             eNotIso
         };
         State eState = eNone;
-        short const * const pType = rNumFor.Info().nTypeArray;
+        auto & rTypeArray = rNumFor.Info().nTypeArray;
         sal_uInt16 nAnz = rNumFor.GetCount();
         for (sal_uInt16 i=0; i < nAnz && !bIsIso && eState != eNotIso; ++i)
         {
-            switch ( pType[i] )
+            switch ( rTypeArray[i] )
             {
             case NF_KEY_YY:     // two digits not strictly ISO 8601
             case NF_KEY_YYYY:
@@ -4652,7 +4638,7 @@ const OUString* SvNumberformat::GetNumForString( sal_uInt16 nNumFor, sal_uInt16
         nPos = nAnz - 1;
         if ( bString )
         {   // Backwards
-            short* pType = NumFor[nNumFor].Info().nTypeArray + nPos;
+            short const * pType = NumFor[nNumFor].Info().nTypeArray.data() + nPos;
             while ( nPos > 0 && (*pType != NF_SYMBOLTYPE_STRING) &&
                     (*pType != NF_SYMBOLTYPE_CURRENCY) )
             {
@@ -4672,7 +4658,7 @@ const OUString* SvNumberformat::GetNumForString( sal_uInt16 nNumFor, sal_uInt16
     else if ( bString )
     {
         // vorwaerts
-        short* pType = NumFor[nNumFor].Info().nTypeArray + nPos;
+        short const * pType = NumFor[nNumFor].Info().nTypeArray.data() + nPos;
         while ( nPos < nAnz && (*pType != NF_SYMBOLTYPE_STRING) &&
                 (*pType != NF_SYMBOLTYPE_CURRENCY) )
         {
@@ -4730,26 +4716,25 @@ bool SvNumberformat::IsNegativeInBracket() const
     {
         return false;
     }
-    OUString *tmpStr = NumFor[1].Info().sStrArray;
-    return tmpStr[0] == "(" && tmpStr[nAnz-1] == ")";
+    auto& tmp = NumFor[1].Info().sStrArray;
+    return tmp[0] == "(" && tmp[nAnz-1] == ")";
 }
 
 bool SvNumberformat::HasPositiveBracketPlaceholder() const
 {
     sal_uInt16 nAnz = NumFor[0].GetCount();
-    OUString *tmpStr = NumFor[0].Info().sStrArray;
-    return tmpStr[nAnz-1] == "_)";
+    return NumFor[0].Info().sStrArray[nAnz-1] == "_)";
 }
 
 DateOrder SvNumberformat::GetDateOrder() const
 {
     if ( (eType & css::util::NumberFormat::DATE) == css::util::NumberFormat::DATE )
     {
-        short const * const pType = NumFor[0].Info().nTypeArray;
+        auto& rTypeArray = NumFor[0].Info().nTypeArray;
         sal_uInt16 nAnz = NumFor[0].GetCount();
         for ( sal_uInt16 j=0; j<nAnz; j++ )
         {
-            switch ( pType[j] )
+            switch ( rTypeArray[j] )
             {
             case NF_KEY_D :
             case NF_KEY_DD :
@@ -4785,12 +4770,12 @@ sal_uInt32 SvNumberformat::GetExactDateOrder() const
         SAL_WARN( "svl.numbers", "SvNumberformat::GetExactDateOrder: no date" );
         return nRet;
     }
-    short const * const pType = NumFor[0].Info().nTypeArray;
+    auto& rTypeArray = NumFor[0].Info().nTypeArray;
     sal_uInt16 nAnz = NumFor[0].GetCount();
     int nShift = 0;
     for ( sal_uInt16 j=0; j<nAnz && nShift < 3; j++ )
     {
-        switch ( pType[j] )
+        switch ( rTypeArray[j] )
         {
         case NF_KEY_D :
         case NF_KEY_DD :
@@ -5029,21 +5014,21 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
         sal_uInt32 nCalendarID = 0x0000000; // Excel ID of calendar used in sub-format see tdf#36038
         if ( nAnz )
         {
-            const short* pType = NumFor[n].Info().nTypeArray;
-            const OUString* pStr = NumFor[n].Info().sStrArray;
+            auto& rTypeArray = NumFor[n].Info().nTypeArray;
+            auto& rStrArray = NumFor[n].Info().sStrArray;
             for ( sal_uInt16 j=0; j<nAnz; j++ )
             {
-                if ( 0 <= pType[j] && pType[j] < NF_KEYWORD_ENTRIES_COUNT )
+                if ( 0 <= rTypeArray[j] && rTypeArray[j] < NF_KEYWORD_ENTRIES_COUNT )
                 {
-                    aStr.append( rKeywords[pType[j]] );
-                    if( NF_KEY_NNNN == pType[j] )
+                    aStr.append( rKeywords[rTypeArray[j]] );
+                    if( NF_KEY_NNNN == rTypeArray[j] )
                     {
                         aStr.append( rLocWrp.getLongDateDayOfWeekSep() );
                     }
                 }
                 else
                 {
-                    switch ( pType[j] )
+                    switch ( rTypeArray[j] )
                     {
                     case NF_SYMBOLTYPE_DECSEP :
                         aStr.append( rLocWrp.getNumDecimalSep() );
@@ -5053,7 +5038,7 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
                         break;
                     case NF_SYMBOLTYPE_EXP :
                         aStr.append( rKeywords[NF_KEY_E] );
-                        if ( pStr[j].getLength() > 1 && pStr[j][1] == '+' )
+                        if ( rStrArray[j].getLength() > 1 && rStrArray[j][1] == '+' )
                             aStr.append( "+" );
                         else
                         // tdf#102370: Excel code for exponent without sign
@@ -5070,33 +5055,33 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
                         break;
                     case NF_SYMBOLTYPE_FRACBLANK :
                     case NF_SYMBOLTYPE_STRING :
-                        if ( pStr[j].getLength() == 1 )
+                        if ( rStrArray[j].getLength() == 1 )
                         {
-                            if ( pType[j] == NF_SYMBOLTYPE_STRING )
+                            if ( rTypeArray[j] == NF_SYMBOLTYPE_STRING )
                                 aStr.append( '\\' );
-                            aStr.append( pStr[j] );
+                            aStr.append( rStrArray[j] );
                         }
                         else
                         {
                             aStr.append( '"' );
-                            aStr.append( pStr[j] );
+                            aStr.append( rStrArray[j] );
                             aStr.append( '"' );
                         }
                         break;
                     case NF_SYMBOLTYPE_CALDEL :
-                        if ( pStr[j+1] == "gengou" )
+                        if ( rStrArray[j+1] == "gengou" )
                         {
                             nCalendarID = 0x0030000;
                         }
-                        else if ( pStr[j+1] == "hijri" )
+                        else if ( rStrArray[j+1] == "hijri" )
                         {
                             nCalendarID = 0x0060000;
                         }
-                        else if ( pStr[j+1] == "buddhist" )
+                        else if ( rStrArray[j+1] == "buddhist" )
                         {
                             nCalendarID = 0x0070000;
                         }
-                        else if ( pStr[j+1] == "jewish" )
+                        else if ( rStrArray[j+1] == "jewish" )
                         {
                             nCalendarID = 0x0080000;
                         }
@@ -5105,7 +5090,7 @@ OUString SvNumberformat::GetMappedFormatstring( const NfKeywordTable& rKeywords,
                             j = j+2;
                         break;
                     default:
-                        aStr.append( pStr[j] );
+                        aStr.append( rStrArray[j] );
                     }
                 }
             }
@@ -5443,10 +5428,10 @@ sal_uInt16 SvNumberformat::ImpGetNumForStringElementCount( sal_uInt16 nNumFor )
 {
     sal_uInt16 nCnt = 0;
     sal_uInt16 nAnz = NumFor[nNumFor].GetCount();
-    short const * const pType = NumFor[nNumFor].Info().nTypeArray;
+    auto& rTypeArray = NumFor[nNumFor].Info().nTypeArray;
     for ( sal_uInt16 j=0; j<nAnz; ++j )
     {
-        switch ( pType[j] )
+        switch ( rTypeArray[j] )
         {
         case NF_SYMBOLTYPE_STRING:
         case NF_SYMBOLTYPE_CURRENCY:
diff --git a/svtools/source/control/ctrltool.cxx b/svtools/source/control/ctrltool.cxx
index c4ab3de8dbcf..1586caf4959d 100644
--- a/svtools/source/control/ctrltool.cxx
+++ b/svtools/source/control/ctrltool.cxx
@@ -338,7 +338,6 @@ FontList::FontList(OutputDevice* pDevice, OutputDevice* pDevice2)
     // initialise variables
     mpDev = pDevice;
     mpDev2 = pDevice2;
-    mpSizeAry = nullptr;
 
     // store style names
     maLight         = SvtResId(STR_SVT_STYLE_LIGHT);
@@ -368,9 +367,6 @@ FontList::FontList(OutputDevice* pDevice, OutputDevice* pDevice2)
 
 FontList::~FontList()
 {
-    // delete SizeArray if required
-    delete[] mpSizeAry;
-
     // delete FontMetrics
     ImplFontListFontMetric *pTemp, *pInfo;
     for (auto const& it : m_Entries)
@@ -748,11 +744,7 @@ const FontMetric& FontList::GetFontMetric( sal_Handle hFontMetric )
 const sal_IntPtr* FontList::GetSizeAry( const FontMetric& rInfo ) const
 {
     // first delete Size-Array
-    if ( mpSizeAry )
-    {
-        delete[] const_cast<FontList*>(this)->mpSizeAry;
-        const_cast<FontList*>(this)->mpSizeAry = nullptr;
-    }
+    mpSizeAry.reset();
 
     // use standard sizes if no name
     if ( rInfo.GetFamilyName().isEmpty() )
@@ -775,21 +767,21 @@ const sal_IntPtr* FontList::GetSizeAry( const FontMetric& rInfo ) const
 
     int nRealCount = 0;
     long    nOldHeight = 0;
-    const_cast<FontList*>(this)->mpSizeAry = new sal_IntPtr[nDevSizeCount+1];
+    mpSizeAry.reset(new sal_IntPtr[nDevSizeCount+1] );
     for (int i = 0; i < nDevSizeCount; ++i)
     {
         Size aSize = pDevice->GetDevFontSize( rInfo, i );
         if ( aSize.Height() != nOldHeight )
         {
             nOldHeight = aSize.Height();
-            const_cast<FontList*>(this)->mpSizeAry[nRealCount] = nOldHeight;
+            mpSizeAry[nRealCount] = nOldHeight;
             nRealCount++;
         }
     }
-    const_cast<FontList*>(this)->mpSizeAry[nRealCount] = 0;
+    mpSizeAry[nRealCount] = 0;
 
     pDevice->SetMapMode( aOldMapMode );
-    return mpSizeAry;
+    return mpSizeAry.get();
 }
 
 struct ImplFSNameItem
diff --git a/tools/source/inet/inetstrm.cxx b/tools/source/inet/inetstrm.cxx
index 156a24599190..73b3afc1e5ac 100644
--- a/tools/source/inet/inetstrm.cxx
+++ b/tools/source/inet/inetstrm.cxx
@@ -233,6 +233,7 @@ INetMIMEMessageStream::INetMIMEMessageStream(
     INetMIMEMessage *pMsg, bool headerGenerated):
     pSourceMsg(pMsg),
     bHeaderGenerated(headerGenerated),
+    mvBuffer(BUFFER_SIZE),
     pMsgStrm(nullptr),
     pMsgRead(nullptr),
     pMsgWrite(nullptr),
@@ -242,14 +243,12 @@ INetMIMEMessageStream::INetMIMEMessageStream(
 {
     assert(pMsg != nullptr);
     maMsgBuffer.SetStreamCharSet(RTL_TEXTENCODING_ASCII_US);
-    pBuffer = new sal_Char[BUFFER_SIZE];
-    pRead = pWrite = pBuffer;
+    pRead = pWrite = mvBuffer.data();
 }
 
 INetMIMEMessageStream::~INetMIMEMessageStream()
 {
     delete pChildStrm;
-    delete [] pBuffer;
     delete pMsgStrm;
 }
 
@@ -272,14 +271,14 @@ int INetMIMEMessageStream::Read(sal_Char* pData, sal_uIntPtr nSize)
         else
         {
             // Buffer empty. Reset to <Begin-of-Buffer>.
-            pRead = pWrite = pBuffer;
+            pRead = pWrite = mvBuffer.data();
 
             // Read next message line.
-            int nRead = GetMsgLine(pBuffer, BUFFER_SIZE);
+            int nRead = GetMsgLine(mvBuffer.data(), mvBuffer.size());
             if (nRead > 0)
             {
                 // Set read pointer.
-                pRead = pBuffer + nRead;
+                pRead = mvBuffer.data() + nRead;
             }
             else
             {
diff --git a/xmlhelp/source/cxxhelp/provider/databases.cxx b/xmlhelp/source/cxxhelp/provider/databases.cxx
index 407a9bd0c9b4..3fc71e0f87c1 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.cxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.cxx
@@ -127,8 +127,6 @@ Databases::Databases( bool showBasic,
                       Reference< uno::XComponentContext > const & xContext )
     : m_xContext( xContext ),
       m_bShowBasic(showBasic),
-      m_nCustomCSSDocLength( 0 ),
-      m_pCustomCSSDoc( nullptr ),
       m_aCSS(styleSheet.toAsciiLowerCase()),
       newProdName( "$[officename]" ),
       newProdVersion( "$[officeversion]" ),
@@ -161,10 +159,6 @@ Databases::Databases( bool showBasic,
 
 Databases::~Databases()
 {
-    // release stylesheet
-
-    delete[] m_pCustomCSSDoc;
-
     // unload the databases
 
     {
@@ -945,15 +939,13 @@ Reference< XHierarchicalNameAccess > Databases::findJarFileForPath
 void Databases::changeCSS(const OUString& newStyleSheet)
 {
     m_aCSS = newStyleSheet.toAsciiLowerCase();
-    delete[] m_pCustomCSSDoc;
-    m_pCustomCSSDoc = nullptr;
-    m_nCustomCSSDocLength = 0;
+    m_vCustomCSSDoc.clear();
 }
 
 void Databases::cascadingStylesheet( const OUString& Language,
                                      OStringBuffer& buffer )
 {
-    if( ! m_pCustomCSSDoc )
+    if( m_vCustomCSSDoc.empty() )
     {
         int retry = 2;
         bool error = true;
@@ -1028,11 +1020,10 @@ void Databases::cascadingStylesheet( const OUString& Language,
             {
                 sal_uInt64 nSize;
                 aFile.getSize( nSize );
-                m_nCustomCSSDocLength = (int)nSize;
-                m_pCustomCSSDoc = new char[ 1 + m_nCustomCSSDocLength ];
-                m_pCustomCSSDoc[ m_nCustomCSSDocLength ] = 0;
-                sal_uInt64 a = m_nCustomCSSDocLength,b = m_nCustomCSSDocLength;
-                aFile.read( m_pCustomCSSDoc,a,b );
+                m_vCustomCSSDoc.resize( nSize + 1);
+                m_vCustomCSSDoc[nSize] = 0;
+                sal_uInt64 a = nSize,b = nSize;
+                aFile.read( m_vCustomCSSDoc.data(), a, b );
                 aFile.close();
                 error = false;
             }
@@ -1049,12 +1040,12 @@ void Databases::cascadingStylesheet( const OUString& Language,
 
         if( error )
         {
-            m_nCustomCSSDocLength = 0;
-            m_pCustomCSSDoc = new char[ 1 ]; // Initialize with 1 to avoid gcc compiler warning
+            m_vCustomCSSDoc.clear();
         }
     }
 
-    buffer.append( m_pCustomCSSDoc, m_nCustomCSSDocLength );
+    if (!m_vCustomCSSDoc.empty())
+        buffer.append( m_vCustomCSSDoc.data(), m_vCustomCSSDoc.size() - 1 );
 }
 
 void Databases::setActiveText( const OUString& Module,
diff --git a/xmlhelp/source/cxxhelp/provider/databases.hxx b/xmlhelp/source/cxxhelp/provider/databases.hxx
index 032a39d93848..9a6fd0296b49 100644
--- a/xmlhelp/source/cxxhelp/provider/databases.hxx
+++ b/xmlhelp/source/cxxhelp/provider/databases.hxx
@@ -235,8 +235,7 @@ namespace chelp {
 
         bool   m_bShowBasic;
 
-        int    m_nCustomCSSDocLength;
-        char*  m_pCustomCSSDoc;
+        std::vector<char> m_vCustomCSSDoc;
         OUString m_aCSS;
 
         enum {
diff --git a/xmlscript/source/xml_helper/xml_impctx.cxx b/xmlscript/source/xml_helper/xml_impctx.cxx
index 18c1666d7d4c..09ec1373cd0d 100644
--- a/xmlscript/source/xml_helper/xml_impctx.cxx
+++ b/xmlscript/source/xml_helper/xml_impctx.cxx
@@ -303,7 +303,7 @@ class ExtendedAttributes :
     public ::cppu::WeakImplHelper< xml::input::XAttributes >
 {
     sal_Int32 m_nAttributes;
-    sal_Int32 * m_pUids;
+    std::unique_ptr<sal_Int32[]> m_pUids;
     OUString * m_pLocalNames;
     OUString * m_pQNames;
     OUString * m_pValues;
@@ -355,7 +355,6 @@ inline ExtendedAttributes::ExtendedAttributes(
 
 ExtendedAttributes::~ExtendedAttributes() throw ()
 {
-    delete [] m_pUids;
     delete [] m_pLocalNames;
     delete [] m_pQNames;
     delete [] m_pValues;


More information about the Libreoffice-commits mailing list