Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: fpdfsdk/javascript/util.cpp

Issue 1838543002: Add test for util.byteToChar() and fix error msg. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: static cast. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/resources/javascript/util_bytetochar.in » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/javascript/util.cpp
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index f7b2d7fbfa51556cb1a475e39aa359ff516e64fe..0f50daf38c41d3ab07bb298a2e2a882c0607d531 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -446,13 +446,17 @@ FX_BOOL util::byteToChar(IJS_Context* cc,
const std::vector<CJS_Value>& params,
CJS_Value& vRet,
CFX_WideString& sError) {
- int iSize = params.size();
- if (iSize == 0)
+ CJS_Context* pContext = static_cast<CJS_Context*>(cc);
+ if (params.size() < 1) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
+ return FALSE;
+ }
+ int arg = params[0].ToInt();
+ if (arg < 0 || arg > 255) {
+ sError = JSGetStringFromID(pContext, IDS_STRING_JSVALUEERROR);
return FALSE;
- int nByte = params[0].ToInt();
- unsigned char cByte = (unsigned char)nByte;
- CFX_WideString csValue;
- csValue.Format(L"%c", cByte);
- vRet = csValue.c_str();
+ }
+ CFX_WideString wStr(static_cast<FX_WCHAR>(arg));
+ vRet = wStr.c_str();
return TRUE;
}
« no previous file with comments | « no previous file | testing/resources/javascript/util_bytetochar.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698