From 30029419ad4b9e5cd382767a8645677afbeff7fd Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 13 Aug 2018 19:56:29 +0000 Subject: Use CFX_ReadOnlyMemoryStream in more places. More const pointers, less const_casts. BUG=pdfium:263 Change-Id: I47fc6d8f2f837390e40ad22d8b67946065294eaa Reviewed-on: https://pdfium-review.googlesource.com/39879 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- xfa/fxfa/cxfa_ffdoc.cpp | 7 +++---- xfa/fxfa/parser/cxfa_document_parser.cpp | 6 +++--- xfa/fxfa/parser/cxfa_node.cpp | 23 ++++++++++------------- xfa/fxfa/parser/cxfa_xmllocale.cpp | 4 ++-- 4 files changed, 18 insertions(+), 22 deletions(-) (limited to 'xfa') diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 330572ff9c..7852d30036 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -14,7 +14,7 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfdoc/cpdf_nametree.h" -#include "core/fxcrt/cfx_memorystream.h" +#include "core/fxcrt/cfx_readonlymemorystream.h" #include "core/fxcrt/cfx_seekablemultistream.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_memory.h" @@ -215,9 +215,8 @@ RetainPtr CXFA_FFDoc::GetPDFNamedImage( auto pAcc = pdfium::MakeRetain(pStream); pAcc->LoadAllDataFiltered(); - RetainPtr pImageFileRead = - pdfium::MakeRetain( - const_cast(pAcc->GetData()), pAcc->GetSize(), false); + auto pImageFileRead = pdfium::MakeRetain( + pAcc->GetData(), pAcc->GetSize()); RetainPtr pDibSource = XFA_LoadImageFromBuffer( pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 96c031079b..5cb08863c8 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -10,7 +10,7 @@ #include #include "core/fxcrt/autorestorer.h" -#include "core/fxcrt/cfx_memorystream.h" +#include "core/fxcrt/cfx_readonlymemorystream.h" #include "core/fxcrt/cfx_widetextbuf.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" @@ -332,8 +332,8 @@ bool CXFA_DocumentParser::Parse( } CFX_XMLNode* CXFA_DocumentParser::ParseXMLData(const ByteString& wsXML) { - auto pStream = pdfium::MakeRetain( - const_cast(wsXML.raw_str()), wsXML.GetLength(), false); + auto pStream = pdfium::MakeRetain( + wsXML.raw_str(), wsXML.GetLength()); xml_doc_ = LoadXML(pStream); if (!xml_doc_) return nullptr; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 8babe45ef3..06bbb0936a 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -15,7 +15,7 @@ #include "core/fxcrt/autorestorer.h" #include "core/fxcrt/cfx_decimal.h" -#include "core/fxcrt/cfx_memorystream.h" +#include "core/fxcrt/cfx_readonlymemorystream.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/locale_iface.h" @@ -200,24 +200,22 @@ RetainPtr XFA_LoadImageData(CXFA_FFDoc* pDoc, FXCODEC_IMAGE_TYPE type = XFA_GetImageType(pImage->GetContentType()); ByteString bsContent; - uint8_t* pImageBuffer = nullptr; + std::vector buffer; RetainPtr pImageFileRead; if (wsImage.GetLength() > 0) { XFA_AttributeEnum iEncoding = pImage->GetTransferEncoding(); if (iEncoding == XFA_AttributeEnum::Base64) { ByteString bsData = wsImage.UTF8Encode(); - int32_t iLength = bsData.GetLength(); - pImageBuffer = FX_Alloc(uint8_t, iLength); - int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer); + buffer.resize(bsData.GetLength()); + int32_t iRead = XFA_Base64Decode(bsData.c_str(), buffer.data()); if (iRead > 0) { pImageFileRead = - pdfium::MakeRetain(pImageBuffer, iRead, false); + pdfium::MakeRetain(buffer.data(), iRead); } } else { bsContent = wsImage.ToDefANSI(); - pImageFileRead = pdfium::MakeRetain( - const_cast(bsContent.raw_str()), bsContent.GetLength(), - false); + pImageFileRead = pdfium::MakeRetain( + bsContent.raw_str(), bsContent.GetLength()); } } else { WideString wsURL = wsHref; @@ -231,16 +229,15 @@ RetainPtr XFA_LoadImageData(CXFA_FFDoc* pDoc, } pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL); } - if (!pImageFileRead) { - FX_Free(pImageBuffer); + if (!pImageFileRead) return nullptr; - } + bNameImage = false; RetainPtr pBitmap = XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi); - FX_Free(pImageBuffer); return pBitmap; } + bool SplitDateTime(const WideString& wsDateTime, WideString& wsDate, WideString& wsTime) { diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp index e4858e907e..2806a084d6 100644 --- a/xfa/fxfa/parser/cxfa_xmllocale.cpp +++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp @@ -8,7 +8,7 @@ #include -#include "core/fxcrt/cfx_memorystream.h" +#include "core/fxcrt/cfx_readonlymemorystream.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/xml/cfx_xmldocument.h" #include "core/fxcrt/xml/cfx_xmlelement.h" @@ -32,7 +32,7 @@ constexpr wchar_t kCurrencySymbol[] = L"currencySymbol"; std::unique_ptr CXFA_XMLLocale::Create( pdfium::span data) { auto stream = - pdfium::MakeRetain(data.data(), data.size(), false); + pdfium::MakeRetain(data.data(), data.size()); CFX_XMLParser parser(stream); auto doc = parser.Parse(); if (!doc) -- cgit v1.2.3