From 77192c1bcbae89ddc8e293cc06bd54e0315f1f08 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 28 Mar 2019 10:32:35 +0200 Subject: loplugin:useuniqueptr in PDFReader Change-Id: I22a96bbf9266cc8dfbe223b985d0ba005a6367e9 Reviewed-on: https://gerrit.libreoffice.org/69881 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sdext/source/pdfimport/inc/pdfparse.hxx | 4 ++-- sdext/source/pdfimport/pdfparse/pdfparse.cxx | 14 +++++++------- sdext/source/pdfimport/test/pdfunzip.cxx | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'sdext/source') diff --git a/sdext/source/pdfimport/inc/pdfparse.hxx b/sdext/source/pdfimport/inc/pdfparse.hxx index e8fcd77f7863..719766e7db98 100644 --- a/sdext/source/pdfimport/inc/pdfparse.hxx +++ b/sdext/source/pdfimport/inc/pdfparse.hxx @@ -291,9 +291,9 @@ class PDFReader public: PDFReader() {} - static PDFEntry* read( const char* pFileName ); + static std::unique_ptr read( const char* pFileName ); #ifdef _WIN32 - static PDFEntry* read( const char* pBuffer, unsigned int nLen ); + static std::unique_ptr read( const char* pBuffer, unsigned int nLen ); #endif }; diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx b/sdext/source/pdfimport/pdfparse/pdfparse.cxx index 42d4c231a336..60ab775ccda5 100644 --- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx @@ -550,7 +550,7 @@ public: }; #ifdef _WIN32 -PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) +std::unique_ptr PDFReader::read( const char* pBuffer, unsigned int nLen ) { PDFGrammar aGrammar( pBuffer ); @@ -581,11 +581,11 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) #endif } - PDFEntry* pRet = nullptr; + std::unique_ptr pRet; unsigned int nEntries = aGrammar.m_aObjectStack.size(); if( nEntries == 1 ) { - pRet = aGrammar.m_aObjectStack.back(); + pRet.reset(aGrammar.m_aObjectStack.back()); aGrammar.m_aObjectStack.pop_back(); } #if OSL_DEBUG_LEVEL > 0 @@ -597,7 +597,7 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) } #endif -PDFEntry* PDFReader::read( const char* pFileName ) +std::unique_ptr PDFReader::read( const char* pFileName ) { #ifdef _WIN32 /* #i106583# @@ -608,7 +608,7 @@ PDFEntry* PDFReader::read( const char* pFileName ) So for the time being bite the bullet and read the whole file. FIXME: give Spirit 2.x another try when we upgrade boost again. */ - PDFEntry* pRet = nullptr; + std::unique_ptr pRet; FILE* fp = fopen( pFileName, "rb" ); if( fp ) { @@ -660,11 +660,11 @@ PDFEntry* PDFReader::read( const char* pFileName ) #endif } - PDFEntry* pRet = nullptr; + std::unique_ptr pRet; unsigned int nEntries = aGrammar.m_aObjectStack.size(); if( nEntries == 1 ) { - pRet = aGrammar.m_aObjectStack.back(); + pRet.reset(aGrammar.m_aObjectStack.back()); aGrammar.m_aObjectStack.pop_back(); } #if OSL_DEBUG_LEVEL > 0 diff --git a/sdext/source/pdfimport/test/pdfunzip.cxx b/sdext/source/pdfimport/test/pdfunzip.cxx index ca7e5afa0b1a..7db906bb255e 100644 --- a/sdext/source/pdfimport/test/pdfunzip.cxx +++ b/sdext/source/pdfimport/test/pdfunzip.cxx @@ -217,10 +217,10 @@ static int handleFile( const char* pInFile, const char* pOutFile, const char* pP PDFReader aParser; int nRet = 0; - PDFEntry* pEntry = pdfparse::PDFReader::read( pInFile ); + std::unique_ptr pEntry = pdfparse::PDFReader::read( pInFile ); if( pEntry ) { - PDFFile* pPDFFile = dynamic_cast(pEntry); + PDFFile* pPDFFile = dynamic_cast(pEntry.get()); if( pPDFFile ) { fprintf( stdout, "have a %s PDF file\n", pPDFFile->isEncrypted() ? "encrypted" : "unencrypted" ); @@ -231,7 +231,6 @@ static int handleFile( const char* pInFile, const char* pOutFile, const char* pP } else nRet = 20; - delete pEntry; } return nRet; } -- cgit