summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/app.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-06-22 15:13:36 -0700
committerLei Zhang <thestig@chromium.org>2015-06-22 15:13:36 -0700
commit5ab3fc60fc44aca144607416d18e7efdc1203fe6 (patch)
treea87fb76fff5cbb9865cddb6b593afc347b02c381 /fpdfsdk/src/javascript/app.cpp
parent06864f7992891d555f9f86efcf4feb06a2856b36 (diff)
downloadpdfium-5ab3fc60fc44aca144607416d18e7efdc1203fe6.tar.xz
Cleanup: Remove more checks for new returning NULL.
R=jam@chromium.org Review URL: https://codereview.chromium.org/1198903002.
Diffstat (limited to 'fpdfsdk/src/javascript/app.cpp')
-rw-r--r--fpdfsdk/src/javascript/app.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/fpdfsdk/src/javascript/app.cpp b/fpdfsdk/src/javascript/app.cpp
index 9d992d0189..31e313179e 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"
@@ -894,26 +895,27 @@ FX_BOOL app::response(IFXJS_Context* cc, const CJS_Parameters& params, CJS_Value
CPDFDoc_Environment* pApp = pContext->GetReaderApp();
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);
- if (nLengthBytes <= 0)
- {
- vRet.SetNull();
- delete[] pBuff;
- return FALSE;
- }
- if (nLengthBytes > MAX_INPUT_BYTES)
- nLengthBytes = MAX_INPUT_BYTES;
-
- vRet = CFX_WideString::FromUTF16LE((unsigned short*)pBuff, nLengthBytes / sizeof(unsigned short)).c_str();
- delete[] pBuff;
- return TRUE;
+ const int MAX_INPUT_BYTES = 2048;
+ 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();
+ return FALSE;
+ }
+ nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
+
+ CFX_WideString ret_string =
+ CFX_WideString::FromUTF16LE((unsigned short*)pBuff.get(),
+ nLengthBytes / sizeof(unsigned short));
+ vRet = ret_string.c_str();
+ return TRUE;
}
FX_BOOL app::media(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)