summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpdfsdk/cpdfsdk_formfillenvironment.cpp66
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp26
2 files changed, 40 insertions, 52 deletions
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
index 6c6e3673e8..e1b34ce51a 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -114,14 +114,14 @@ CFX_WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() {
if (nRequiredLen <= 0)
return CFX_WideString();
- std::unique_ptr<char[]> pBuff(new char[nRequiredLen]);
- memset(pBuff.get(), 0, nRequiredLen);
+ std::vector<uint8_t> pBuff(nRequiredLen);
const int nActualLen = m_pInfo->m_pJsPlatform->Field_browse(
- m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen);
+ m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
if (nActualLen <= 0 || nActualLen > nRequiredLen)
return CFX_WideString();
- return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen));
+ pBuff.resize(nActualLen);
+ return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff));
}
CFX_WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() {
@@ -134,14 +134,14 @@ CFX_WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() {
if (nRequiredLen <= 0)
return CFX_WideString();
- std::unique_ptr<char[]> pBuff(new char[nRequiredLen]);
- memset(pBuff.get(), 0, nRequiredLen);
+ std::vector<uint8_t> pBuff(nRequiredLen);
const int nActualLen = m_pInfo->m_pJsPlatform->Doc_getFilePath(
- m_pInfo->m_pJsPlatform, pBuff.get(), nRequiredLen);
+ m_pInfo->m_pJsPlatform, pBuff.data(), nRequiredLen);
if (nActualLen <= 0 || nActualLen > nRequiredLen)
return CFX_WideString();
- return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff.get(), nActualLen));
+ pBuff.resize(nActualLen);
+ return CFX_WideString::FromLocal(CFX_ByteStringC(pBuff));
}
void CPDFSDK_FormFillEnvironment::JS_docSubmitForm(void* formData,
@@ -368,25 +368,20 @@ void CPDFSDK_FormFillEnvironment::SetCurrentPage(FPDF_DOCUMENT document,
CFX_WideString CPDFSDK_FormFillEnvironment::GetPlatform() {
if (!m_pInfo || !m_pInfo->FFI_GetPlatform)
- return L"";
+ return CFX_WideString();
int nRequiredLen = m_pInfo->FFI_GetPlatform(m_pInfo, nullptr, 0);
if (nRequiredLen <= 0)
- return L"";
+ return CFX_WideString();
- char* pbuff = new char[nRequiredLen];
- memset(pbuff, 0, nRequiredLen);
- int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
- if (nActualLen <= 0 || nActualLen > nRequiredLen) {
- delete[] pbuff;
- return L"";
- }
- CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
- CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
- (unsigned short*)bsRet.GetBuffer(bsRet.GetLength()),
- bsRet.GetLength() / sizeof(unsigned short));
- delete[] pbuff;
- return wsRet;
+ std::vector<uint8_t> pBuff(nRequiredLen);
+ int nActualLen =
+ m_pInfo->FFI_GetPlatform(m_pInfo, pBuff.data(), nRequiredLen);
+ if (nActualLen <= 0 || nActualLen > nRequiredLen)
+ return CFX_WideString();
+
+ return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
+ nActualLen / sizeof(uint16_t));
}
void CPDFSDK_FormFillEnvironment::GotoURL(FPDF_DOCUMENT document,
@@ -533,25 +528,20 @@ FPDF_BOOL CPDFSDK_FormFillEnvironment::PutRequestURL(const wchar_t* wsURL,
CFX_WideString CPDFSDK_FormFillEnvironment::GetLanguage() {
if (!m_pInfo || !m_pInfo->FFI_GetLanguage)
- return L"";
+ return CFX_WideString();
int nRequiredLen = m_pInfo->FFI_GetLanguage(m_pInfo, nullptr, 0);
if (nRequiredLen <= 0)
- return L"";
+ return CFX_WideString();
- char* pbuff = new char[nRequiredLen];
- memset(pbuff, 0, nRequiredLen);
- int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
- if (nActualLen <= 0 || nActualLen > nRequiredLen) {
- delete[] pbuff;
- return L"";
- }
- CFX_ByteString bsRet = CFX_ByteString(pbuff, nActualLen);
- CFX_WideString wsRet = CFX_WideString::FromUTF16LE(
- (FPDF_WIDESTRING)bsRet.GetBuffer(bsRet.GetLength()),
- bsRet.GetLength() / sizeof(FPDF_WIDESTRING));
- delete[] pbuff;
- return wsRet;
+ std::vector<uint8_t> pBuff(nRequiredLen);
+ int nActualLen =
+ m_pInfo->FFI_GetLanguage(m_pInfo, pBuff.data(), nRequiredLen);
+ if (nActualLen <= 0 || nActualLen > nRequiredLen)
+ return CFX_WideString();
+
+ return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
+ nActualLen / sizeof(uint16_t));
}
void CPDFSDK_FormFillEnvironment::PageEvent(int iPageCount,
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 57735426e7..bda0128f18 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -6,6 +6,7 @@
#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
+#include <algorithm>
#include <utility>
#include "core/fpdfapi/parser/cpdf_document.h"
@@ -307,25 +308,22 @@ CFX_WideString CPDFXFA_Context::Response(const CFX_WideString& wsQuestion,
const CFX_WideString& wsTitle,
const CFX_WideString& wsDefaultAnswer,
bool bMark) {
- CFX_WideString wsAnswer;
if (!m_pFormFillEnv)
- return wsAnswer;
+ return CFX_WideString();
int nLength = 2048;
- char* pBuff = new char[nLength];
+ std::vector<uint8_t> pBuff(nLength);
nLength = m_pFormFillEnv->JS_appResponse(wsQuestion.c_str(), wsTitle.c_str(),
wsDefaultAnswer.c_str(), nullptr,
- bMark, pBuff, nLength);
- if (nLength > 0) {
- nLength = nLength > 2046 ? 2046 : nLength;
- pBuff[nLength] = 0;
- pBuff[nLength + 1] = 0;
- wsAnswer = CFX_WideString::FromUTF16LE(
- reinterpret_cast<const unsigned short*>(pBuff),
- nLength / sizeof(unsigned short));
- }
- delete[] pBuff;
- return wsAnswer;
+ bMark, pBuff.data(), nLength);
+ if (nLength <= 0)
+ return CFX_WideString();
+
+ nLength = std::min(2046, nLength);
+ pBuff[nLength] = 0;
+ pBuff[nLength + 1] = 0;
+ return CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
+ nLength / sizeof(uint16_t));
}
CFX_RetainPtr<IFX_SeekableReadStream> CPDFXFA_Context::DownloadURL(