[Libreoffice-commits] core.git: sdext/source

Noel Grandin noel.grandin at collabora.co.uk
Tue Jan 17 10:12:22 UTC 2017


 sdext/source/pdfimport/inc/pdfparse.hxx               |   11 ++----
 sdext/source/pdfimport/pdfparse/pdfentries.cxx        |   29 +++++++++---------
 sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx |    1 
 sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx |    3 +
 4 files changed, 22 insertions(+), 22 deletions(-)

New commits:
commit 88c755e37cd36ddfe6d0d651540d9f2bd8a029a6
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jan 17 10:12:40 2017 +0200

    new loplugin: useuniqueptr: sdext
    
    Change-Id: Iae1dfc7f566d2f5bd1652f170218b502b5663126
    Reviewed-on: https://gerrit.libreoffice.org/33205
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sdext/source/pdfimport/inc/pdfparse.hxx b/sdext/source/pdfimport/inc/pdfparse.hxx
index a43bfbb..d368286 100644
--- a/sdext/source/pdfimport/inc/pdfparse.hxx
+++ b/sdext/source/pdfimport/inc/pdfparse.hxx
@@ -26,6 +26,7 @@
 
 #include <unordered_map>
 #include <vector>
+#include <memory>
 
 namespace pdfparse
 {
@@ -50,7 +51,7 @@ public:
 
 private:
     friend struct PDFEntry;
-    EmitImplData* m_pImplData;
+    std::unique_ptr<EmitImplData> m_pImplData;
 };
 
 struct PDFEntry
@@ -227,17 +228,13 @@ struct PDFFileImplData;
 struct PDFFile : public PDFContainer
 {
 private:
-    mutable PDFFileImplData*    m_pData;
+    mutable std::unique_ptr<PDFFileImplData> m_pData;
     PDFFileImplData*            impl_getData() const;
 public:
     unsigned int        m_nMajor;           // PDF major
     unsigned int        m_nMinor;           // PDF minor
 
-    PDFFile()
-    : PDFContainer(),
-      m_pData( nullptr ),
-      m_nMajor( 0 ), m_nMinor( 0 )
-    {}
+    PDFFile();
     virtual ~PDFFile() override;
 
     virtual bool emit( EmitContext& rWriteContext ) const override;
diff --git a/sdext/source/pdfimport/pdfparse/pdfentries.cxx b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
index ab8a2b9..87dda7d 100644
--- a/sdext/source/pdfimport/pdfparse/pdfentries.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfentries.cxx
@@ -97,12 +97,11 @@ EmitContext::EmitContext( const PDFContainer* pTop ) :
     m_pImplData( nullptr )
 {
     if( pTop )
-        m_pImplData = new EmitImplData( pTop );
+        m_pImplData.reset( new EmitImplData( pTop ) );
 }
 
 EmitContext::~EmitContext()
 {
-    delete m_pImplData;
 }
 
 PDFEntry::~PDFEntry()
@@ -111,14 +110,14 @@ PDFEntry::~PDFEntry()
 
 EmitImplData* PDFEntry::getEmitData( EmitContext& rContext )
 {
-    return rContext.m_pImplData;
+    return rContext.m_pImplData.get();
 }
 
 void PDFEntry::setEmitData( EmitContext& rContext, EmitImplData* pNewEmitData )
 {
-    if( rContext.m_pImplData && rContext.m_pImplData != pNewEmitData )
-        delete rContext.m_pImplData;
-    rContext.m_pImplData = pNewEmitData;
+    if( rContext.m_pImplData && rContext.m_pImplData.get() != pNewEmitData )
+        rContext.m_pImplData.reset();
+    rContext.m_pImplData.reset( pNewEmitData );
 }
 
 PDFValue::~PDFValue()
@@ -1051,9 +1050,13 @@ struct PDFFileImplData
 };
 }
 
+PDFFile::PDFFile()
+   : PDFContainer(), m_nMajor( 0 ), m_nMinor( 0 )
+{
+}
+
 PDFFile::~PDFFile()
 {
-    delete m_pData;
 }
 
 bool PDFFile::isEncrypted() const
@@ -1223,7 +1226,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const
         m_pData->m_aDigest = rtl_digest_createMD5();
 
     // first try user password
-    bool bValid = check_user_password( rPwd, m_pData );
+    bool bValid = check_user_password( rPwd, m_pData.get() );
 
     if( ! bValid )
     {
@@ -1232,7 +1235,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const
         sal_uInt8 aKey[ENCRYPTION_KEY_LEN];
         sal_uInt8 nPwd[ENCRYPTION_BUF_LEN];
         memset( nPwd, 0, sizeof(nPwd) );
-        sal_uInt32 nKeyLen = password_to_key( rPwd, aKey, m_pData, true );
+        sal_uInt32 nKeyLen = password_to_key( rPwd, aKey, m_pData.get(), true );
         if( m_pData->m_nStandardRevision == 2 )
         {
             rtl_cipher_initARCFOUR( m_pData->m_aCipher, rtl_Cipher_DirectionDecode,
@@ -1256,7 +1259,7 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const
                                           nPwd, 32 ); // decrypt inplace
             }
         }
-        bValid = check_user_password( OString( reinterpret_cast<char*>(nPwd), 32 ), m_pData );
+        bValid = check_user_password( OString( reinterpret_cast<char*>(nPwd), 32 ), m_pData.get() );
     }
 
     return bValid;
@@ -1265,8 +1268,8 @@ bool PDFFile::setupDecryptionData( const OString& rPwd ) const
 PDFFileImplData* PDFFile::impl_getData() const
 {
     if( m_pData )
-        return m_pData;
-    m_pData = new PDFFileImplData();
+        return m_pData.get();
+    m_pData.reset( new PDFFileImplData );
     // check for encryption dict in a trailer
     unsigned int nElements = m_aSubElements.size();
     while( nElements-- > 0 )
@@ -1400,7 +1403,7 @@ PDFFileImplData* PDFFile::impl_getData() const
         }
     }
 
-    return m_pData;
+    return m_pData.get();
 }
 
 bool PDFFile::emit( EmitContext& rWriteContext ) const
diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
index 5c09619..5d4a797 100644
--- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
+++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx
@@ -534,7 +534,6 @@ PDFOutDev::PDFOutDev( PDFDoc* pDoc ) :
 }
 PDFOutDev::~PDFOutDev()
 {
-    delete m_pUtf8Map;
 }
 
 void PDFOutDev::startPage(int /*pageNum*/, GfxState* state
diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx
index d060cde..f6d6fa4 100644
--- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx
+++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx
@@ -48,6 +48,7 @@
 
 #include <unordered_map>
 #include <vector>
+#include <memory>
 
 class GfxPath;
 class GfxFont;
@@ -134,7 +135,7 @@ namespace pdfi
         PDFDoc*                                 m_pDoc;
         mutable std::unordered_map< long long,
                                FontAttributes > m_aFontMap;
-        UnicodeMap*                             m_pUtf8Map;
+        std::unique_ptr<UnicodeMap>             m_pUtf8Map;
         bool                                    m_bSkipImages;
 
         int  parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;


More information about the Libreoffice-commits mailing list