From fef49bc5e23e860fc9d3529839d1a4eb684feafc Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Mon, 5 Jan 2015 10:06:47 -0800 Subject: Fixed incorrect use of FX_WSTRC on FX_WCHAR* vars. FX_WSTRC is only valid on arrays, not pointers. In five places it was being passed a pointer, which leads to incorrect string objects being created. This was found when integrating a change to FX_WSTRC that disallows pointer arguments. The consequence of this bug is that five XML strings (quot, amp, apos, lt, and gt) will all end up with incorrect lengths. They will all be one character long in 32-bit builds, and three characters long in 64-bit builds (sizeof(WCHAR*)-1). Also removed some unneeded casts and marked some arrays as const. Fixing this is necessary in order to allow landing of https://codereview.chromium.org/818193004/ Testing this was attempted by using the xfa branch of pdfium in Chrome: cd third_party\pdfium git checkout xfa However even without these changes this caused a CHECK failure in V8::InitializePlatform due to double initialization, so the fix has not been tested, but is clearly an improvement. BUG= https://code.google.com/p/pdfium/issues/detail?id=96 R=bo_xu@foxitsoftware.com Review URL: https://codereview.chromium.org/826573003 --- xfa/src/fxfa/src/fm2js/xfa_fm2jscontext.cpp | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/xfa/src/fxfa/src/fm2js/xfa_fm2jscontext.cpp b/xfa/src/fxfa/src/fm2js/xfa_fm2jscontext.cpp index 3f44b5d254..330bfcfcf5 100644 --- a/xfa/src/fxfa/src/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/src/fxfa/src/fm2js/xfa_fm2jscontext.cpp @@ -3861,12 +3861,12 @@ void CXFA_FM2JSContext::DecodeXML (FX_BSTR szXMLString, CFX_ByteTextBuf &szResu ++i; continue; } - FX_WCHAR *strName[] = { - (FX_WCHAR *)L"quot", - (FX_WCHAR *)L"amp", - (FX_WCHAR *)L"apos", - (FX_WCHAR *)L"lt", - (FX_WCHAR *)L"gt" + FX_LPCWSTR const strName[] = { + L"quot", + L"amp", + L"apos", + L"lt", + L"gt" }; FX_INT32 iIndex = 0; while (iIndex < 5) { @@ -3958,7 +3958,7 @@ void CXFA_FM2JSContext::EncodeURL (FX_BSTR szURLString, CFX_ByteTextBuf &szResu FX_WCHAR strUnsafe[] = { ' ', '<', '>', '"', '#', '%', '{', '}', '|', '\\', '^', '~', '[', ']', '`' }; FX_WCHAR strReserved[] = {';', '/', '?', ':', '@', '=', '&'}; FX_WCHAR strSpecial[] = {'$', '-', '+', '!', '*', '\'', '(', ')', ','}; - FX_WCHAR* strCode = (FX_WCHAR *)L"0123456789abcdef"; + FX_WCHAR* strCode = L"0123456789abcdef"; for (FX_INT32 u = 0; u < iLength; ++u) { ch = wsURLString.GetAt(u); FX_INT32 i = 0; @@ -4121,14 +4121,14 @@ void CXFA_FM2JSContext::EncodeXML (FX_BSTR szXMLString, CFX_ByteTextBuf &szResu strEncode[6] = 0; strEncode[7] = ';'; strEncode[8] = 0; - FX_WCHAR *strName[] = { - (FX_WCHAR *)L"quot", - (FX_WCHAR *)L"amp", - (FX_WCHAR *)L"apos", - (FX_WCHAR *)L"lt", - (FX_WCHAR *)L"gt" + FX_LPCWSTR const strName[] = { + L"quot", + L"amp", + L"apos", + L"lt", + L"gt" }; - FX_WCHAR* strCode = (FX_WCHAR *)L"0123456789abcdef"; + FX_WCHAR* strCode = L"0123456789abcdef"; FX_WCHAR ch = 0; FX_INT32 iLength = wsXMLString.GetLength(); FX_INT32 iIndex = 0; @@ -4139,27 +4139,27 @@ void CXFA_FM2JSContext::EncodeXML (FX_BSTR szXMLString, CFX_ByteTextBuf &szResu switch (ch) { case '"': wsResultBuf.AppendChar('&'); - wsResultBuf << FX_WSTRC(strName[QUOT]); + wsResultBuf << CFX_WideStringC(strName[QUOT]); wsResultBuf.AppendChar(';'); break; case '&': wsResultBuf.AppendChar('&'); - wsResultBuf << FX_WSTRC(strName[AMP]); + wsResultBuf << CFX_WideStringC(strName[AMP]); wsResultBuf.AppendChar(';'); break; case '\'': wsResultBuf.AppendChar('&'); - wsResultBuf << FX_WSTRC(strName[APOS]); + wsResultBuf << CFX_WideStringC(strName[APOS]); wsResultBuf.AppendChar(';'); break; case '<': wsResultBuf.AppendChar('&'); - wsResultBuf << FX_WSTRC(strName[LT]); + wsResultBuf << CFX_WideStringC(strName[LT]); wsResultBuf.AppendChar(';'); break; case '>': wsResultBuf.AppendChar('&'); - wsResultBuf << FX_WSTRC(strName[GT]); + wsResultBuf << CFX_WideStringC(strName[GT]); wsResultBuf.AppendChar(';'); break; default: { -- cgit v1.2.3