From 4ad46903002d9dff92b3f05d34a7ff73d74ee2c1 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 2 May 2017 13:19:56 -0700 Subject: Remove some |new|s in cpdfsdk_formfillenvironment.cpp and cpdfxfa_context.cpp Use std::vector as buffer instead. Change-Id: I710fe87f292b2c0f838410e9c7ff615c27c589a6 Reviewed-on: https://pdfium-review.googlesource.com/4790 Reviewed-by: dsinclair Commit-Queue: Tom Sepez --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'fpdfsdk/fpdfxfa') 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 #include #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 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(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(pBuff.data()), + nLength / sizeof(uint16_t)); } CFX_RetainPtr CPDFXFA_Context::DownloadURL( -- cgit v1.2.3