Kaydet (Commit) 77192c1b authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in PDFReader

Change-Id: I22a96bbf9266cc8dfbe223b985d0ba005a6367e9
Reviewed-on: https://gerrit.libreoffice.org/69881
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst bf1114a8
...@@ -291,9 +291,9 @@ class PDFReader ...@@ -291,9 +291,9 @@ class PDFReader
public: public:
PDFReader() {} PDFReader() {}
static PDFEntry* read( const char* pFileName ); static std::unique_ptr<PDFEntry> read( const char* pFileName );
#ifdef _WIN32 #ifdef _WIN32
static PDFEntry* read( const char* pBuffer, unsigned int nLen ); static std::unique_ptr<PDFEntry> read( const char* pBuffer, unsigned int nLen );
#endif #endif
}; };
......
...@@ -550,7 +550,7 @@ public: ...@@ -550,7 +550,7 @@ public:
}; };
#ifdef _WIN32 #ifdef _WIN32
PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) std::unique_ptr<PDFEntry> PDFReader::read( const char* pBuffer, unsigned int nLen )
{ {
PDFGrammar<const char*> aGrammar( pBuffer ); PDFGrammar<const char*> aGrammar( pBuffer );
...@@ -581,11 +581,11 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) ...@@ -581,11 +581,11 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen )
#endif #endif
} }
PDFEntry* pRet = nullptr; std::unique_ptr<PDFEntry> pRet;
unsigned int nEntries = aGrammar.m_aObjectStack.size(); unsigned int nEntries = aGrammar.m_aObjectStack.size();
if( nEntries == 1 ) if( nEntries == 1 )
{ {
pRet = aGrammar.m_aObjectStack.back(); pRet.reset(aGrammar.m_aObjectStack.back());
aGrammar.m_aObjectStack.pop_back(); aGrammar.m_aObjectStack.pop_back();
} }
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
...@@ -597,7 +597,7 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen ) ...@@ -597,7 +597,7 @@ PDFEntry* PDFReader::read( const char* pBuffer, unsigned int nLen )
} }
#endif #endif
PDFEntry* PDFReader::read( const char* pFileName ) std::unique_ptr<PDFEntry> PDFReader::read( const char* pFileName )
{ {
#ifdef _WIN32 #ifdef _WIN32
/* #i106583# /* #i106583#
...@@ -608,7 +608,7 @@ PDFEntry* PDFReader::read( const char* pFileName ) ...@@ -608,7 +608,7 @@ PDFEntry* PDFReader::read( const char* pFileName )
So for the time being bite the bullet and read the whole file. 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. FIXME: give Spirit 2.x another try when we upgrade boost again.
*/ */
PDFEntry* pRet = nullptr; std::unique_ptr<PDFEntry> pRet;
FILE* fp = fopen( pFileName, "rb" ); FILE* fp = fopen( pFileName, "rb" );
if( fp ) if( fp )
{ {
...@@ -660,11 +660,11 @@ PDFEntry* PDFReader::read( const char* pFileName ) ...@@ -660,11 +660,11 @@ PDFEntry* PDFReader::read( const char* pFileName )
#endif #endif
} }
PDFEntry* pRet = nullptr; std::unique_ptr<PDFEntry> pRet;
unsigned int nEntries = aGrammar.m_aObjectStack.size(); unsigned int nEntries = aGrammar.m_aObjectStack.size();
if( nEntries == 1 ) if( nEntries == 1 )
{ {
pRet = aGrammar.m_aObjectStack.back(); pRet.reset(aGrammar.m_aObjectStack.back());
aGrammar.m_aObjectStack.pop_back(); aGrammar.m_aObjectStack.pop_back();
} }
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
......
...@@ -217,10 +217,10 @@ static int handleFile( const char* pInFile, const char* pOutFile, const char* pP ...@@ -217,10 +217,10 @@ static int handleFile( const char* pInFile, const char* pOutFile, const char* pP
PDFReader aParser; PDFReader aParser;
int nRet = 0; int nRet = 0;
PDFEntry* pEntry = pdfparse::PDFReader::read( pInFile ); std::unique_ptr<PDFEntry> pEntry = pdfparse::PDFReader::read( pInFile );
if( pEntry ) if( pEntry )
{ {
PDFFile* pPDFFile = dynamic_cast<PDFFile*>(pEntry); PDFFile* pPDFFile = dynamic_cast<PDFFile*>(pEntry.get());
if( pPDFFile ) if( pPDFFile )
{ {
fprintf( stdout, "have a %s PDF file\n", pPDFFile->isEncrypted() ? "encrypted" : "unencrypted" ); 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 ...@@ -231,7 +231,6 @@ static int handleFile( const char* pInFile, const char* pOutFile, const char* pP
} }
else else
nRet = 20; nRet = 20;
delete pEntry;
} }
return nRet; return nRet;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment