diff options
author | Lei Zhang <thestig@chromium.org> | 2015-10-02 10:11:43 -0700 |
---|---|---|
committer | Lei Zhang <thestig@chromium.org> | 2015-10-02 10:11:43 -0700 |
commit | db5256fb4ad0678ab7f895c40391cb77a3ba40fa (patch) | |
tree | ccb11617298e0aba0f740e9361d7ecc3e6f4135f /fpdfsdk/src | |
parent | cb78ef507c272488fd7e4fd6862014333d8a9de5 (diff) | |
download | pdfium-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 .
Diffstat (limited to 'fpdfsdk/src')
-rw-r--r-- | fpdfsdk/src/javascript/app.cpp | 25 |
1 files changed, 10 insertions, 15 deletions
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; } |