summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_interform.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-13 21:32:50 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-13 21:32:50 +0000
commit2ee811f24c98ac3900a164118ab976be6c3c9bab (patch)
treebdf79dcb9ef035d19d5ce284ebcc9180065879a0 /fpdfsdk/cpdfsdk_interform.cpp
parent4f1aa69662adf8e7038ed3abd6a36fc338119487 (diff)
downloadpdfium-2ee811f24c98ac3900a164118ab976be6c3c9bab.tar.xz
Use std::vector in FDFToURLEncodedData().
Simplify memory management. Change-Id: Ie17b96fa53dff79f6cb8131d7a8ffc6a0e3f6a34 Reviewed-on: https://pdfium-review.googlesource.com/39972 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_interform.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp48
1 files changed, 13 insertions, 35 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 3cd1b67b26..55b9f7cc44 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -78,9 +78,9 @@ bool IsFormFieldTypeXFA(FormFieldType fieldType) {
}
#endif // PDF_ENABLE_XFA
-bool FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize) {
+bool FDFToURLEncodedData(std::vector<uint8_t>* pBuffer) {
std::unique_ptr<CFDF_Document> pFDF =
- CFDF_Document::ParseMemory(pBuf, nBufSize);
+ CFDF_Document::ParseMemory(pBuffer->data(), pBuffer->size());
if (!pFDF)
return true;
@@ -108,12 +108,12 @@ bool FDFToURLEncodedData(uint8_t*& pBuf, size_t& nBufSize) {
fdfEncodedData << "&";
}
- nBufSize = fdfEncodedData.tellp();
+ size_t nBufSize = fdfEncodedData.tellp();
if (nBufSize <= 0)
return false;
- pBuf = FX_Alloc(uint8_t, nBufSize);
- memcpy(pBuf, fdfEncodedData.str().c_str(), nBufSize);
+ pBuffer->resize(nBufSize);
+ memcpy(pBuffer->data(), fdfEncodedData.str().c_str(), nBufSize);
return true;
}
@@ -505,22 +505,12 @@ bool CPDFSDK_InterForm::SubmitFields(const WideString& csDestination,
if (nBufSize == 0)
return false;
- uint8_t* pLocalBuffer = FX_Alloc(uint8_t, nBufSize);
- memcpy(pLocalBuffer, textBuf.c_str(), nBufSize);
- uint8_t* pBuffer = pLocalBuffer;
-
- if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) {
- FX_Free(pLocalBuffer);
+ std::vector<uint8_t> buffer(nBufSize);
+ memcpy(buffer.data(), textBuf.c_str(), nBufSize);
+ if (bUrlEncoded && !FDFToURLEncodedData(&buffer))
return false;
- }
-
- m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination);
-
- if (pBuffer != pLocalBuffer)
- FX_Free(pBuffer);
-
- FX_Free(pLocalBuffer);
+ m_pFormFillEnv->JS_docSubmitForm(buffer.data(), buffer.size(), csDestination);
return true;
}
@@ -547,27 +537,15 @@ bool CPDFSDK_InterForm::SubmitForm(const WideString& sDestination,
return false;
ByteString fdfBuffer = pFDFDoc->WriteToString();
-
if (fdfBuffer.IsEmpty())
return false;
- uint8_t* pLocalBuffer = FX_Alloc(uint8_t, fdfBuffer.GetLength());
- memcpy(pLocalBuffer, fdfBuffer.c_str(), fdfBuffer.GetLength());
-
- uint8_t* pBuffer = pLocalBuffer;
- size_t nBufSize = fdfBuffer.GetLength();
- if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) {
- FX_Free(pLocalBuffer);
+ std::vector<uint8_t> buffer(fdfBuffer.GetLength());
+ memcpy(buffer.data(), fdfBuffer.c_str(), fdfBuffer.GetLength());
+ if (bUrlEncoded && !FDFToURLEncodedData(&buffer))
return false;
- }
-
- m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination);
-
- if (pBuffer != pLocalBuffer)
- FX_Free(pBuffer);
-
- FX_Free(pLocalBuffer);
+ m_pFormFillEnv->JS_docSubmitForm(buffer.data(), buffer.size(), sDestination);
return true;
}