summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-13 23:19:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-13 23:19:29 +0000
commited176992eb7ddbb0fee7b79625501df06f8ccf93 (patch)
treeab5493b058e80da342648fda8b0cc8a8ba6cab94 /core
parentf0260b2cccb9e6c59413a20040dccf5551fb6882 (diff)
downloadpdfium-ed176992eb7ddbb0fee7b79625501df06f8ccf93.tar.xz
Make CFX_ReadOnlyMemoryStream take a span.
Change-Id: Id097320ab2d9b5d1579582e5797e29c701499501 Reviewed-on: https://pdfium-review.googlesource.com/39991 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp3
-rw-r--r--core/fpdfdoc/cpdf_metadata.cpp3
-rw-r--r--core/fxcrt/cfx_readonlymemorystream.cpp16
-rw-r--r--core/fxcrt/cfx_readonlymemorystream.h6
4 files changed, 13 insertions, 15 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index d37c8d5457..421af48d80 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -32,8 +32,7 @@ std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(
pdfium::span<const uint8_t> span) {
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
- pDoc->ParseStream(
- pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(span.data(), span.size()));
+ pDoc->ParseStream(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(span));
return pDoc->m_pRootDict ? std::move(pDoc) : nullptr;
}
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index b9a92963dd..99fd965452 100644
--- a/core/fpdfdoc/cpdf_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -67,8 +67,7 @@ std::vector<UnsupportedFeature> CPDF_Metadata::CheckForSharedForm() const {
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(stream_.Get());
pAcc->LoadAllDataFiltered();
- auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pAcc->GetData(),
- pAcc->GetSize());
+ auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pAcc->GetSpan());
CFX_XMLParser parser(stream);
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
if (!doc)
diff --git a/core/fxcrt/cfx_readonlymemorystream.cpp b/core/fxcrt/cfx_readonlymemorystream.cpp
index 1d09759208..a01ed2e474 100644
--- a/core/fxcrt/cfx_readonlymemorystream.cpp
+++ b/core/fxcrt/cfx_readonlymemorystream.cpp
@@ -8,14 +8,14 @@
#include "core/fxcrt/fx_safe_types.h"
-CFX_ReadOnlyMemoryStream::CFX_ReadOnlyMemoryStream(const uint8_t* pBuf,
- FX_FILESIZE size)
- : m_pBuf(pBuf), m_size(size) {}
+CFX_ReadOnlyMemoryStream::CFX_ReadOnlyMemoryStream(
+ pdfium::span<const uint8_t> span)
+ : m_span(span) {}
CFX_ReadOnlyMemoryStream::~CFX_ReadOnlyMemoryStream() = default;
FX_FILESIZE CFX_ReadOnlyMemoryStream::GetSize() {
- return m_size;
+ return pdfium::base::checked_cast<FX_FILESIZE>(m_span.size());
}
bool CFX_ReadOnlyMemoryStream::ReadBlock(void* buffer,
@@ -24,11 +24,11 @@ bool CFX_ReadOnlyMemoryStream::ReadBlock(void* buffer,
if (offset < 0)
return false;
- FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
- newPos += offset;
- if (!newPos.IsValid() || newPos.ValueOrDie() > m_size)
+ FX_SAFE_SIZE_T pos = size;
+ pos += offset;
+ if (!pos.IsValid() || pos.ValueOrDie() > m_span.size())
return false;
- memcpy(buffer, m_pBuf + offset, size);
+ memcpy(buffer, &m_span[offset], size);
return true;
}
diff --git a/core/fxcrt/cfx_readonlymemorystream.h b/core/fxcrt/cfx_readonlymemorystream.h
index e9d18222a4..a6645b82c7 100644
--- a/core/fxcrt/cfx_readonlymemorystream.h
+++ b/core/fxcrt/cfx_readonlymemorystream.h
@@ -9,6 +9,7 @@
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/span.h"
class CFX_ReadOnlyMemoryStream final : public IFX_SeekableReadStream {
public:
@@ -20,11 +21,10 @@ class CFX_ReadOnlyMemoryStream final : public IFX_SeekableReadStream {
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
private:
- CFX_ReadOnlyMemoryStream(const uint8_t* pBuf, FX_FILESIZE size);
+ explicit CFX_ReadOnlyMemoryStream(pdfium::span<const uint8_t> span);
~CFX_ReadOnlyMemoryStream() override;
- const uint8_t* const m_pBuf;
- const FX_FILESIZE m_size;
+ const pdfium::span<const uint8_t> m_span;
};
#endif // CORE_FXCRT_CFX_READONLYMEMORYSTREAM_H_