From 90d87793cf55f3c4e57e9db6c8de692ebef41e29 Mon Sep 17 00:00:00 2001 From: tsepez Date: Tue, 29 Mar 2016 09:21:54 -0700 Subject: Add test for util.byteToChar() and fix error msg. Review URL: https://codereview.chromium.org/1838543002 --- fpdfsdk/javascript/util.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'fpdfsdk/javascript') diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp index f7b2d7fbfa..0f50daf38c 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& params, CJS_Value& vRet, CFX_WideString& sError) { - int iSize = params.size(); - if (iSize == 0) + CJS_Context* pContext = static_cast(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(arg)); + vRet = wStr.c_str(); return TRUE; } -- cgit v1.2.3