summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-02 10:11:43 -0700
committerLei Zhang <thestig@chromium.org>2015-10-02 10:11:43 -0700
commitdb5256fb4ad0678ab7f895c40391cb77a3ba40fa (patch)
treeccb11617298e0aba0f740e9361d7ecc3e6f4135f
parentcb78ef507c272488fd7e4fd6862014333d8a9de5 (diff)
downloadpdfium-db5256fb4ad0678ab7f895c40391cb77a3ba40fa.tar.xz
XFA: Remove more checks for new returning NULL.
This is partially based on https://codereview.chromium.org/1198903002/ R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1377733005 .
-rw-r--r--fpdfsdk/include/fsdk_mgr.h9
-rw-r--r--fpdfsdk/src/javascript/app.cpp25
2 files changed, 11 insertions, 23 deletions
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index b76b16bd07..d53a21e94a 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -239,9 +239,6 @@ class CPDFDoc_Environment final {
return L"";
char* pbuff = new char[nRequiredLen];
- if (!pbuff)
- return L"";
-
memset(pbuff, 0, nRequiredLen);
int nActualLen = m_pInfo->FFI_GetPlatform(m_pInfo, pbuff, nRequiredLen);
if (nActualLen <= 0 || nActualLen > nRequiredLen) {
@@ -353,8 +350,7 @@ class CPDFDoc_Environment final {
FPDF_LPFILEHANDLER fileHandler =
m_pInfo->FFI_DownloadFromURL(m_pInfo, wsURL);
- CFPDF_FileStream* fileStream = new CFPDF_FileStream(fileHandler);
- return fileStream;
+ return new CFPDF_FileStream(fileHandler);
}
return NULL;
}
@@ -433,9 +429,6 @@ class CPDFDoc_Environment final {
return L"";
char* pbuff = new char[nRequiredLen];
- if (!pbuff)
- return L"";
-
memset(pbuff, 0, nRequiredLen);
int nActualLen = m_pInfo->FFI_GetLanguage(m_pInfo, pbuff, nRequiredLen);
if (nActualLen <= 0 || nActualLen > nRequiredLen) {
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 2cdb1ad616..9ea50d90cb 100644
--- a/fpdfsdk/src/javascript/app.cpp
+++ b/fpdfsdk/src/javascript/app.cpp
@@ -4,6 +4,7 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "../../../third_party/base/nonstd_unique_ptr.h"
#include "../../include/javascript/JavaScript.h"
#include "../../include/javascript/IJavaScript.h"
#include "../../include/javascript/JS_Define.h"
@@ -838,26 +839,20 @@ FX_BOOL app::response(IFXJS_Context* cc,
ASSERT(pApp != NULL);
const int MAX_INPUT_BYTES = 2048;
- char* pBuff = new char[MAX_INPUT_BYTES + 2];
- if (!pBuff)
- return FALSE;
-
- memset(pBuff, 0, MAX_INPUT_BYTES + 2);
- int nLengthBytes = pApp->JS_appResponse(swQuestion.c_str(), swTitle.c_str(),
- swDefault.c_str(), swLabel.c_str(),
- bPassWord, pBuff, MAX_INPUT_BYTES);
+ nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
+ memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
+ int nLengthBytes = pApp->JS_appResponse(
+ swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
+ bPassWord, pBuff.get(), MAX_INPUT_BYTES);
if (nLengthBytes <= 0) {
vRet.SetNull();
- delete[] pBuff;
return FALSE;
}
- if (nLengthBytes > MAX_INPUT_BYTES)
- nLengthBytes = MAX_INPUT_BYTES;
+ nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
- vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff,
- nLengthBytes / sizeof(unsigned short))
- .c_str();
- delete[] pBuff;
+ CFX_WideString ret_string = CFX_WideString::FromUTF16LE(
+ (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short));
+ vRet = ret_string.c_str();
return TRUE;
}