[Libreoffice-commits] core.git: vcl/headless vcl/inc vcl/source vcl/unx

Noel Grandin noel.grandin at collabora.co.uk
Mon Jul 10 10:40:05 UTC 2017


 vcl/headless/svpgdi.cxx                        |   21 ++----
 vcl/inc/textlineinfo.hxx                       |   11 +--
 vcl/source/filter/igif/decode.cxx              |   20 ++---
 vcl/source/filter/igif/decode.hxx              |    8 +-
 vcl/source/font/fontcharmap.cxx                |   11 +--
 vcl/source/gdi/pngread.cxx                     |   84 ++++++++++++-------------
 vcl/source/outdev/text.cxx                     |   21 ------
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx |   19 ++---
 vcl/unx/generic/print/bitmap_gfx.cxx           |   14 +---
 9 files changed, 92 insertions(+), 117 deletions(-)

New commits:
commit 804cd2bd56295c5cb039b55ac7ca880c17399bad
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Jul 10 09:48:28 2017 +0200

    loplugin:useuniqueptr in vcl
    
    Change-Id: Ieece2f9728755a8ae91275535eaa39319eea274e
    Reviewed-on: https://gerrit.libreoffice.org/39740
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index c694fc0c7161..f72797cd5835 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -171,16 +171,16 @@ namespace
                 // the alpha values need to be inverted for Cairo
                 // so big stupid copy and invert here
                 const int nImageSize = pMaskBuf->mnHeight * pMaskBuf->mnScanlineSize;
-                pAlphaBits = new unsigned char[nImageSize];
-                memcpy(pAlphaBits, pMaskBuf->mpBits, nImageSize);
+                pAlphaBits.reset( new unsigned char[nImageSize] );
+                memcpy(pAlphaBits.get(), pMaskBuf->mpBits, nImageSize);
 
                 // TODO: make upper layers use standard alpha
-                sal_uInt32* pLDst = reinterpret_cast<sal_uInt32*>(pAlphaBits);
+                sal_uInt32* pLDst = reinterpret_cast<sal_uInt32*>(pAlphaBits.get());
                 for( int i = nImageSize/sizeof(sal_uInt32); --i >= 0; ++pLDst )
                     *pLDst = ~*pLDst;
-                assert(reinterpret_cast<unsigned char*>(pLDst) == pAlphaBits+nImageSize);
+                assert(reinterpret_cast<unsigned char*>(pLDst) == pAlphaBits.get()+nImageSize);
 
-                mask = cairo_image_surface_create_for_data(pAlphaBits,
+                mask = cairo_image_surface_create_for_data(pAlphaBits.get(),
                                                 CAIRO_FORMAT_A8,
                                                 pMaskBuf->mnWidth, pMaskBuf->mnHeight,
                                                 pMaskBuf->mnScanlineSize);
@@ -190,15 +190,15 @@ namespace
                 // the alpha values need to be inverted for Cairo
                 // so big stupid copy and invert here
                 const int nImageSize = pMaskBuf->mnHeight * pMaskBuf->mnScanlineSize;
-                pAlphaBits = new unsigned char[nImageSize];
-                memcpy(pAlphaBits, pMaskBuf->mpBits, nImageSize);
+                pAlphaBits.reset( new unsigned char[nImageSize] );
+                memcpy(pAlphaBits.get(), pMaskBuf->mpBits, nImageSize);
 
                 // TODO: make upper layers use standard alpha
-                unsigned char* pDst = pAlphaBits;
+                unsigned char* pDst = pAlphaBits.get();
                 for (int i = nImageSize; --i >= 0; ++pDst)
                     *pDst = ~*pDst;
 
-                mask = cairo_image_surface_create_for_data(pAlphaBits,
+                mask = cairo_image_surface_create_for_data(pAlphaBits.get(),
                                                 CAIRO_FORMAT_A1,
                                                 pMaskBuf->mnWidth, pMaskBuf->mnHeight,
                                                 pMaskBuf->mnScanlineSize);
@@ -207,7 +207,6 @@ namespace
         ~MaskHelper()
         {
             cairo_surface_destroy(mask);
-            delete[] pAlphaBits;
         }
         cairo_surface_t* getMask()
         {
@@ -215,7 +214,7 @@ namespace
         }
     private:
         cairo_surface_t *mask;
-        unsigned char* pAlphaBits;
+        std::unique_ptr<unsigned char[]> pAlphaBits;
 
         MaskHelper(const MaskHelper&) = delete;
         MaskHelper& operator=(const MaskHelper&) = delete;
diff --git a/vcl/inc/textlineinfo.hxx b/vcl/inc/textlineinfo.hxx
index 519aa489c9e0..03b19ede96e6 100644
--- a/vcl/inc/textlineinfo.hxx
+++ b/vcl/inc/textlineinfo.hxx
@@ -20,6 +20,9 @@
 #ifndef INCLUDED_VCL_INC_TEXTLINEINFO_HXX
 #define INCLUDED_VCL_INC_TEXTLINEINFO_HXX
 
+#include <memory>
+#include <vector>
+
 class ImplTextLineInfo
 {
 private:
@@ -52,16 +55,14 @@ public:
     void        Clear();
 
     ImplTextLineInfo* GetLine( sal_Int32 nLine ) const
-                            { return mpLines[nLine]; }
-    sal_Int32   Count() const { return mnLines; }
+                            { return mvLines[nLine].get(); }
+    sal_Int32   Count() const { return mvLines.size(); }
 
 private:
     ImplMultiTextLineInfo( const ImplMultiTextLineInfo& ) = delete;
     ImplMultiTextLineInfo& operator=( const ImplMultiTextLineInfo& ) = delete;
 
-    ImplTextLineInfo**  mpLines;
-    sal_Int32   mnLines;
-    sal_Int32   mnSize;
+    std::vector<std::unique_ptr<ImplTextLineInfo>>  mvLines;
 
 };
 
diff --git a/vcl/source/filter/igif/decode.cxx b/vcl/source/filter/igif/decode.cxx
index 9647fc97ab3a..bbbbee27d10d 100644
--- a/vcl/source/filter/igif/decode.cxx
+++ b/vcl/source/filter/igif/decode.cxx
@@ -38,31 +38,27 @@ GIFLZWDecompressor::GIFLZWDecompressor(sal_uInt8 cDataSize)
     , nBlockBufSize(0)
     , nBlockBufPos(0)
 {
-    pOutBuf = new sal_uInt8[ 4096 ];
-
     nClearCode = 1 << nDataSize;
     nEOICode = nClearCode + 1;
     nTableSize = nEOICode + 1;
     nCodeSize = nDataSize + 1;
     nOldCode = 0xffff;
-    pOutBufData = pOutBuf + 4096;
+    pOutBufData = pOutBuf.data() + 4096;
 
-    pTable = new GIFLZWTableEntry[ 4098 ];
+    pTable.reset( new GIFLZWTableEntry[ 4098 ] );
 
     for (sal_uInt16 i = 0; i < nTableSize; ++i)
     {
         pTable[i].pPrev = nullptr;
-        pTable[i].pFirst = pTable + i;
+        pTable[i].pFirst = pTable.get() + i;
         pTable[i].nData = (sal_uInt8) i;
     }
 
-    memset(pTable + nTableSize, 0, sizeof(GIFLZWTableEntry) * (4098 - nTableSize));
+    memset(pTable.get() + nTableSize, 0, sizeof(GIFLZWTableEntry) * (4098 - nTableSize));
 }
 
 GIFLZWDecompressor::~GIFLZWDecompressor()
 {
-    delete[] pOutBuf;
-    delete[] pTable;
 }
 
 Scanline GIFLZWDecompressor::DecompressBlock( sal_uInt8* pSrc, sal_uInt8 cBufSize,
@@ -113,8 +109,8 @@ bool GIFLZWDecompressor::AddToTable( sal_uInt16 nPrevCode, sal_uInt16 nCodeFirst
 {
     if( nTableSize < 4096 )
     {
-        GIFLZWTableEntry* pE = pTable + nTableSize;
-        pE->pPrev = pTable + nPrevCode;
+        GIFLZWTableEntry* pE = pTable.get() + nTableSize;
+        pE->pPrev = pTable.get() + nPrevCode;
         pE->pFirst = pE->pPrev->pFirst;
         GIFLZWTableEntry *pEntry = pTable[nCodeFirstData].pFirst;
         if (!pEntry)
@@ -196,10 +192,10 @@ bool GIFLZWDecompressor::ProcessOneCode()
             return false;
 
         // write character(/-sequence) of code nCode in the output buffer:
-        GIFLZWTableEntry* pE = pTable + nCode;
+        GIFLZWTableEntry* pE = pTable.get() + nCode;
         do
         {
-            if (pOutBufData == pOutBuf) //can't go back past start
+            if (pOutBufData == pOutBuf.data()) //can't go back past start
                 return false;
             nOutBufDataLen++;
             *(--pOutBufData) = pE->nData;
diff --git a/vcl/source/filter/igif/decode.hxx b/vcl/source/filter/igif/decode.hxx
index 0983958ef679..fb9d65527264 100644
--- a/vcl/source/filter/igif/decode.hxx
+++ b/vcl/source/filter/igif/decode.hxx
@@ -21,13 +21,17 @@
 #define INCLUDED_VCL_SOURCE_FILTER_IGIF_DECODE_HXX
 
 #include <vcl/bitmapaccess.hxx>
+#include <array>
+#include <memory>
 
 struct GIFLZWTableEntry;
 
 class GIFLZWDecompressor
 {
-    GIFLZWTableEntry*       pTable;
-    sal_uInt8*              pOutBuf;
+    std::unique_ptr<GIFLZWTableEntry[]>
+                            pTable;
+    std::array<sal_uInt8, 4096>
+                            pOutBuf;
     sal_uInt8*              pOutBufData;
     sal_uInt8*              pBlockBuf;
     sal_uLong               nInputBitsBuf;
diff --git a/vcl/source/font/fontcharmap.cxx b/vcl/source/font/fontcharmap.cxx
index b1a6fef9d4ff..8d5137db308f 100644
--- a/vcl/source/font/fontcharmap.cxx
+++ b/vcl/source/font/fontcharmap.cxx
@@ -38,11 +38,12 @@ static const sal_UCS4 aDefaultSymbolRanges[] = {0x0020,0x0100, 0xF020,0xF100};
 
 ImplFontCharMap::~ImplFontCharMap()
 {
-    if( isDefaultMap() )
-        return;
-    delete[] mpRangeCodes;
-    delete[] mpStartGlyphs;
-    delete[] mpGlyphIds;
+    if( !isDefaultMap() )
+    {
+        delete[] mpRangeCodes;
+        delete[] mpStartGlyphs;
+        delete[] mpGlyphIds;
+    }
 }
 
 ImplFontCharMap::ImplFontCharMap( const CmapResult& rCR )
diff --git a/vcl/source/gdi/pngread.cxx b/vcl/source/gdi/pngread.cxx
index 688d017edca1..8dde053a7d82 100644
--- a/vcl/source/gdi/pngread.cxx
+++ b/vcl/source/gdi/pngread.cxx
@@ -85,9 +85,12 @@ private:
     BitmapWriteAccess*         mpMaskAcc;
 
     ZCodec              mpZCodec;
-    sal_uInt8*          mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1
-    sal_uInt8*          mpScanPrior;    // pointer to the latest scanline
-    sal_uInt8*          mpTransTab;     // for transparency in images with palette colortype
+    std::unique_ptr<sal_uInt8[]>
+                        mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1
+    std::unique_ptr<sal_uInt8[]>
+                        mpScanPrior;    // pointer to the latest scanline
+    std::unique_ptr<sal_uInt8[]>
+                        mpTransTab;     // for transparency in images with palette colortype
     sal_uInt8*          mpScanCurrent;  // pointer into the current scanline
     sal_uInt8*          mpColorTable;
     std::size_t         mnStreamSize;   // estimate of PNG file size
@@ -133,8 +136,10 @@ private:
     sal_Int32           mnAllocSizeScanlineAlpha;
 #endif
     // the temporary Scanline (and alpha) for direct scanline copy to Bitmap
-    sal_uInt8*          mpScanline;
-    sal_uInt8*          mpScanlineAlpha;
+    std::unique_ptr<sal_uInt8[]>
+                        mpScanline;
+    std::unique_ptr<sal_uInt8[]>
+                        mpScanlineAlpha;
 
     bool                ReadNextChunk();
     void                ReadRemainingChunks();
@@ -244,13 +249,6 @@ PNGReaderImpl::~PNGReaderImpl()
 
     if( mpColorTable != mpDefaultColorTable )
         delete[] mpColorTable;
-
-    delete[] mpTransTab;
-    delete[] mpInflateInBuf;
-    delete[] mpScanPrior;
-
-    delete[] mpScanline;
-    delete[] mpScanlineAlpha;
 }
 
 bool PNGReaderImpl::ReadNextChunk()
@@ -652,9 +650,9 @@ bool PNGReaderImpl::ImplReadHeader( const Size& rPreviewSizeHint )
     }
 
     // TODO: switch between both scanlines instead of copying
-    mpInflateInBuf = new (std::nothrow) sal_uInt8[ mnScansize ];
-    mpScanCurrent = mpInflateInBuf;
-    mpScanPrior = new (std::nothrow) sal_uInt8[ mnScansize ];
+    mpInflateInBuf.reset( new (std::nothrow) sal_uInt8[ mnScansize ] );
+    mpScanCurrent = mpInflateInBuf.get();
+    mpScanPrior.reset( new (std::nothrow) sal_uInt8[ mnScansize ] );
 
     if ( !mpInflateInBuf || !mpScanPrior )
         return false;
@@ -736,8 +734,8 @@ bool PNGReaderImpl::ImplReadTransparent()
             {
                 if ( mnChunkLen == 2 )
                 {
-                    mpTransTab = new sal_uInt8[ 256 ];
-                    memset( mpTransTab, 0xff, 256);
+                    mpTransTab.reset( new sal_uInt8[ 256 ] );
+                    memset( mpTransTab.get(), 0xff, 256);
                     // color type 0 and 4 is always greyscale,
                     // so the return value can be used as index
                     sal_uInt8 nIndex = ImplScaleColor();
@@ -764,11 +762,11 @@ bool PNGReaderImpl::ImplReadTransparent()
                 if ( mnChunkLen <= 256 )
                 {
                     mbTransparent = true;
-                    mpTransTab = new sal_uInt8 [ 256 ];
-                    memset( mpTransTab, 0xff, 256 );
+                    mpTransTab.reset( new sal_uInt8 [ 256 ] );
+                    memset( mpTransTab.get(), 0xff, 256 );
                     if (mnChunkLen > 0)
                     {
-                        memcpy( mpTransTab, &(*maDataIter), mnChunkLen );
+                        memcpy( mpTransTab.get(), &(*maDataIter), mnChunkLen );
                         maDataIter += mnChunkLen;
                         // need alpha transparency if not on/off masking
                         for( int i = 0; i < mnChunkLen; ++i )
@@ -905,7 +903,7 @@ void PNGReaderImpl::ImplReadIDAT()
         while ( mpZCodec.GetBreak() )
         {
             // get bytes needed to fill the current scanline
-            sal_Int32 nToRead = mnScansize - (mpScanCurrent - mpInflateInBuf);
+            sal_Int32 nToRead = mnScansize - (mpScanCurrent - mpInflateInBuf.get());
             sal_Int32 nRead = mpZCodec.ReadAsynchron( aIStrm, mpScanCurrent, nToRead );
             if ( nRead < 0 )
             {
@@ -919,7 +917,7 @@ void PNGReaderImpl::ImplReadIDAT()
             }
             else  // this scanline is Finished
             {
-                mpScanCurrent = mpInflateInBuf;
+                mpScanCurrent = mpInflateInBuf.get();
                 ImplApplyFilter();
 
                 ImplDrawScanline( mnXStart, mnXAdd );
@@ -1001,7 +999,7 @@ bool PNGReaderImpl::ImplPreparePass()
     mnScansize = ( mnScansize*mnPngDepth + 7 ) >> 3;
 
     ++mnScansize; // scan size also needs room for the filtertype byte
-    memset( mpScanPrior, 0, mnScansize );
+    memset( mpScanPrior.get(), 0, mnScansize );
 
     return true;
 }
@@ -1012,9 +1010,9 @@ bool PNGReaderImpl::ImplPreparePass()
 void PNGReaderImpl::ImplApplyFilter()
 {
     OSL_ASSERT( mnScansize >= mnBPP + 1 );
-    const sal_uInt8* const pScanEnd = mpInflateInBuf + mnScansize;
+    const sal_uInt8* const pScanEnd = mpInflateInBuf.get() + mnScansize;
 
-    sal_uInt8 nFilterType = *mpInflateInBuf; // the filter type may change each scanline
+    sal_uInt8 nFilterType = mpInflateInBuf[0]; // the filter type may change each scanline
     switch ( nFilterType )
     {
         default: // unknown Scanline Filter Type
@@ -1024,7 +1022,7 @@ void PNGReaderImpl::ImplApplyFilter()
 
         case 1: // Scanline Filter Type "Sub"
         {
-            sal_uInt8* p1 = mpInflateInBuf + 1;
+            sal_uInt8* p1 = mpInflateInBuf.get() + 1;
             const sal_uInt8* p2 = p1;
             p1 += mnBPP;
 
@@ -1039,8 +1037,8 @@ void PNGReaderImpl::ImplApplyFilter()
 
         case 2: // Scanline Filter Type "Up"
         {
-            sal_uInt8* p1 = mpInflateInBuf + 1;
-            const sal_uInt8* p2 = mpScanPrior + 1;
+            sal_uInt8* p1 = mpInflateInBuf.get() + 1;
+            const sal_uInt8* p2 = mpScanPrior.get() + 1;
 
             // use pixels from prior line
             while( p1 < pScanEnd )
@@ -1053,8 +1051,8 @@ void PNGReaderImpl::ImplApplyFilter()
 
         case 3: // Scanline Filter Type "Average"
         {
-            sal_uInt8* p1 = mpInflateInBuf + 1;
-            const sal_uInt8* p2 = mpScanPrior + 1;
+            sal_uInt8* p1 = mpInflateInBuf.get() + 1;
+            const sal_uInt8* p2 = mpScanPrior.get() + 1;
             const sal_uInt8* p3 = p1;
 
             // use one pixel from prior line
@@ -1072,8 +1070,8 @@ void PNGReaderImpl::ImplApplyFilter()
 
         case 4: // Scanline Filter Type "PathPredictor"
         {
-            sal_uInt8* p1 = mpInflateInBuf + 1;
-            const sal_uInt8* p2 = mpScanPrior + 1;
+            sal_uInt8* p1 = mpInflateInBuf.get() + 1;
+            const sal_uInt8* p2 = mpScanPrior.get() + 1;
             const sal_uInt8* p3 = p1;
             const sal_uInt8* p4 = p2;
 
@@ -1114,7 +1112,7 @@ void PNGReaderImpl::ImplApplyFilter()
         break;
     }
 
-    memcpy( mpScanPrior, mpInflateInBuf, mnScansize );
+    memcpy( mpScanPrior.get(), mpInflateInBuf.get(), mnScansize );
 }
 
 namespace
@@ -1163,7 +1161,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
     // => TODO; also do this for nX here instead of in the ImplSet*Pixel() methods
     const sal_uInt32 nY = mnYpos >> mnPreviewShift;
 
-    sal_uInt8* pTmp = mpInflateInBuf + 1;
+    sal_uInt8* pTmp = mpInflateInBuf.get() + 1;
     if ( mxAcc->HasPalette() ) // alphachannel is not allowed by pictures including palette entries
     {
         switch ( mxAcc->GetBitCount() )
@@ -1378,7 +1376,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 #if OSL_DEBUG_LEVEL > 0
                         mnAllocSizeScanline = maOrigSize.Width() * 3;
 #endif
-                        mpScanline = new sal_uInt8[maOrigSize.Width() * 3];
+                        mpScanline.reset( new sal_uInt8[maOrigSize.Width() * 3] );
                     }
 
                     if(!mpScanlineAlpha)
@@ -1386,7 +1384,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 #if OSL_DEBUG_LEVEL > 0
                         mnAllocSizeScanlineAlpha = maOrigSize.Width();
 #endif
-                        mpScanlineAlpha = new sal_uInt8[maOrigSize.Width()];
+                        mpScanlineAlpha.reset( new sal_uInt8[maOrigSize.Width()] );
                     }
                 }
 
@@ -1398,8 +1396,8 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
                     OSL_ENSURE(mnAllocSizeScanline >= maOrigSize.Width() * 3, "Allocated Scanline too small (!)");
                     OSL_ENSURE(mnAllocSizeScanlineAlpha >= maOrigSize.Width(), "Allocated ScanlineAlpha too small (!)");
 #endif
-                    sal_uInt8* pScanline(mpScanline);
-                    sal_uInt8* pScanlineAlpha(mpScanlineAlpha);
+                    sal_uInt8* pScanline(mpScanline.get());
+                    sal_uInt8* pScanlineAlpha(mpScanlineAlpha.get());
 
                     for (long nX(0); nX < maOrigSize.Width(); nX++, pTmp += 4)
                     {
@@ -1423,8 +1421,8 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 
                     // copy scanlines directly to bitmaps for content and alpha; use the formats which
                     // are able to copy directly to BitmapBuffer
-                    mxAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3);
-                    mpMaskAcc->CopyScanline(nY, mpScanlineAlpha, ScanlineFormat::N8BitPal, maOrigSize.Width());
+                    mxAcc->CopyScanline(nY, mpScanline.get(), ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3);
+                    mpMaskAcc->CopyScanline(nY, mpScanlineAlpha.get(), ScanlineFormat::N8BitPal, maOrigSize.Width());
                 }
                 else
                 {
@@ -1523,7 +1521,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 #if OSL_DEBUG_LEVEL > 0
                 mnAllocSizeScanline = maOrigSize.Width() * 3;
 #endif
-                mpScanline = new sal_uInt8[maOrigSize.Width() * 3];
+                mpScanline.reset( new sal_uInt8[maOrigSize.Width() * 3] );
             }
 
             if ( mnPngDepth == 8 )   // maybe the source has 16 bit per sample
@@ -1534,7 +1532,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 #if OSL_DEBUG_LEVEL > 0
                     OSL_ENSURE(mnAllocSizeScanline >= maOrigSize.Width() * 3, "Allocated Scanline too small (!)");
 #endif
-                    sal_uInt8* pScanline(mpScanline);
+                    sal_uInt8* pScanline(mpScanline.get());
 
                     for (long nX(0); nX < maOrigSize.Width(); nX++, pTmp += 3)
                     {
@@ -1555,7 +1553,7 @@ void PNGReaderImpl::ImplDrawScanline( sal_uInt32 nXStart, sal_uInt32 nXAdd )
 
                     // copy scanline directly to bitmap for content; use the format which is able to
                     // copy directly to BitmapBuffer
-                    mxAcc->CopyScanline(nY, mpScanline, ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3);
+                    mxAcc->CopyScanline(nY, mpScanline.get(), ScanlineFormat::N24BitTcBgr, maOrigSize.Width() * 3);
                 }
                 else
                 {
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 580a6c372664..94e46d00224a 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -44,37 +44,20 @@
 
 ImplMultiTextLineInfo::ImplMultiTextLineInfo()
 {
-    mpLines = new ImplTextLineInfo*[MULTITEXTLINEINFO_RESIZE];
-    mnLines = 0;
-    mnSize  = MULTITEXTLINEINFO_RESIZE;
 }
 
 ImplMultiTextLineInfo::~ImplMultiTextLineInfo()
 {
-    for( sal_Int32 i = 0; i < mnLines; i++ )
-        delete mpLines[i];
-    delete [] mpLines;
 }
 
 void ImplMultiTextLineInfo::AddLine( ImplTextLineInfo* pLine )
 {
-    if ( mnSize == mnLines )
-    {
-        mnSize += MULTITEXTLINEINFO_RESIZE;
-        ImplTextLineInfo** pNewLines = new ImplTextLineInfo*[mnSize];
-        memcpy( pNewLines, mpLines, mnLines*sizeof(ImplTextLineInfo*) );
-        mpLines = pNewLines;
-    }
-
-    mpLines[mnLines] = pLine;
-    mnLines++;
+    mvLines.push_back(std::unique_ptr<ImplTextLineInfo>(pLine));
 }
 
 void ImplMultiTextLineInfo::Clear()
 {
-    for( sal_Int32 i = 0; i < mnLines; i++ )
-        delete mpLines[i];
-    mnLines = 0;
+    mvLines.clear();
 }
 
 void OutputDevice::ImplInitTextColor()
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index 0d925b3d690a..6950d3b354ea 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -752,7 +752,6 @@ class PolyArgs
 {
 public:
                 PolyArgs( tools::PolyPolygon& rPolyPoly, sal_uInt16 nMaxPoints );
-                ~PolyArgs();
 
     void        AddPoint( long nX, long nY, PolyFlags);
     void        ClosePolygon();
@@ -763,8 +762,10 @@ public:
 private:
     tools::PolyPolygon& mrPolyPoly;
 
-    Point*          mpPointAry;
-    PolyFlags*      mpFlagAry;
+    std::unique_ptr<Point[]>
+                    mpPointAry;
+    std::unique_ptr<PolyFlags[]>
+                    mpFlagAry;
 
     FT_Vector       maPosition;
     sal_uInt16      mnMaxPoints;
@@ -783,17 +784,11 @@ PolyArgs::PolyArgs( tools::PolyPolygon& rPolyPoly, sal_uInt16 nMaxPoints )
     mnPoly(0),
     bHasOffline(false)
 {
-    mpPointAry  = new Point[ mnMaxPoints ];
-    mpFlagAry   = new PolyFlags [ mnMaxPoints ];
+    mpPointAry.reset( new Point[ mnMaxPoints ] );
+    mpFlagAry.reset( new PolyFlags [ mnMaxPoints ] );
     maPosition.x = maPosition.y = 0;
 }
 
-PolyArgs::~PolyArgs()
-{
-    delete[] mpFlagAry;
-    delete[] mpPointAry;
-}
-
 void PolyArgs::AddPoint( long nX, long nY, PolyFlags aFlag )
 {
     SAL_WARN_IF( (mnPoints >= mnMaxPoints), "vcl", "FTGlyphOutline: AddPoint overflow!" );
@@ -820,7 +815,7 @@ void PolyArgs::ClosePolygon()
     SAL_WARN_IF( (mpFlagAry[0]!=PolyFlags::Normal), "vcl", "FTGlyphOutline: PolyFinishFE failed!" );
     SAL_WARN_IF( (mpFlagAry[mnPoints]!=PolyFlags::Normal), "vcl", "FTGlyphOutline: PolyFinishFS failed!" );
 
-    tools::Polygon aPoly( mnPoints, mpPointAry, (bHasOffline ? mpFlagAry : nullptr) );
+    tools::Polygon aPoly( mnPoints, mpPointAry.get(), (bHasOffline ? mpFlagAry.get() : nullptr) );
 
     // #i35928#
     // This may be a invalid polygons, e.g. the last point is a control point.
diff --git a/vcl/unx/generic/print/bitmap_gfx.cxx b/vcl/unx/generic/print/bitmap_gfx.cxx
index 13051c38db5a..5e43d3b4e32e 100644
--- a/vcl/unx/generic/print/bitmap_gfx.cxx
+++ b/vcl/unx/generic/print/bitmap_gfx.cxx
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <array>
 #include <memory>
 #include "psputil.hxx"
 
@@ -273,7 +274,8 @@ private:
         sal_uInt16      mnValue;        // pixelvalue
     };
 
-    LZWCTreeNode*   mpTable;    // LZW compression data
+    std::array<LZWCTreeNode, 4096>
+                    mpTable;    // LZW compression data
     LZWCTreeNode*   mpPrefix;   // the compression is as same as the TIFF compression
     sal_uInt16      mnDataSize;
     sal_uInt16      mnClearCode;
@@ -306,8 +308,6 @@ LZWEncoder::LZWEncoder(osl::File* pOutputFile) :
     mnOffset    = 32;   // free bits in dwShift
     mdwShift    = 0;
 
-    mpTable = new LZWCTreeNode[ 4096 ];
-
     for (sal_uInt32 i = 0; i < 4096; i++)
     {
         mpTable[i].mpBrother    = nullptr;
@@ -327,8 +327,6 @@ LZWEncoder::~LZWEncoder()
         WriteBits (mpPrefix->mnCode, mnCodeSize);
 
     WriteBits (mnEOICode, mnCodeSize);
-
-    delete[] mpTable;
 }
 
 void
@@ -355,7 +353,7 @@ LZWEncoder::EncodeByte (sal_uInt8 nByte )
 
     if (!mpPrefix)
     {
-        mpPrefix = mpTable + nByte;
+        mpPrefix = mpTable.data() + nByte;
     }
     else
     {
@@ -389,14 +387,14 @@ LZWEncoder::EncodeByte (sal_uInt8 nByte )
                 if(mnTableSize == (sal_uInt16)((1 << mnCodeSize) - 1))
                     mnCodeSize++;
 
-                p = mpTable + (mnTableSize++);
+                p = mpTable.data() + (mnTableSize++);
                 p->mpBrother = mpPrefix->mpFirstChild;
                 mpPrefix->mpFirstChild = p;
                 p->mnValue = nV;
                 p->mpFirstChild = nullptr;
             }
 
-            mpPrefix = mpTable + nV;
+            mpPrefix = mpTable.data() + nV;
         }
     }
 }


More information about the Libreoffice-commits mailing list