From 05e01698444726fae302cd335fa4880932d7c543 Mon Sep 17 00:00:00 2001 From: tsepez Date: Mon, 28 Nov 2016 17:30:09 -0800 Subject: Make FDF document creation return unique_ptrs Review-Url: https://codereview.chromium.org/2538533003 --- fpdfsdk/cpdfsdk_interform.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'fpdfsdk/cpdfsdk_interform.cpp') diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index f8fd3b3db5..a2f07b488f 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -463,7 +463,8 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize) { - CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); + std::unique_ptr pFDF = + CFDF_Document::ParseMemory(pBuf, nBufSize); if (!pFDF) return true; @@ -506,9 +507,9 @@ bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( const std::vector& fields, bool bIncludeOrExclude, CFX_ByteTextBuf& textBuf) { - std::unique_ptr pFDF( + std::unique_ptr pFDF = m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), - fields, bIncludeOrExclude, false)); + fields, bIncludeOrExclude, false); return pFDF ? pFDF->WriteBuf(textBuf) : false; } @@ -525,26 +526,21 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, if (!m_pFormFillEnv || !m_pInterForm) return false; - CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); - CFDF_Document* pFDFDoc = - m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); + std::unique_ptr pFDFDoc = m_pInterForm->ExportToFDF( + m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); if (!pFDFDoc) return false; CFX_ByteTextBuf FdfBuffer; - bool bRet = pFDFDoc->WriteBuf(FdfBuffer); - delete pFDFDoc; - if (!bRet) + if (!pFDFDoc->WriteBuf(FdfBuffer)) return false; uint8_t* pBuffer = FdfBuffer.GetBuffer(); FX_STRSIZE nBufSize = FdfBuffer.GetLength(); - if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) return false; m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); - if (bUrlEncoded) FX_Free(pBuffer); @@ -552,15 +548,9 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, } bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { - CFDF_Document* pFDF = m_pInterForm->ExportToFDF( + std::unique_ptr pFDF = m_pInterForm->ExportToFDF( m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); - if (!pFDF) - return false; - - bool bRet = pFDF->WriteBuf(textBuf); - delete pFDF; - - return bRet; + return pFDF && pFDF->WriteBuf(textBuf); } bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { -- cgit v1.2.3