diff options
author | Lei Zhang <thestig@chromium.org> | 2018-07-25 20:09:58 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-07-25 20:09:58 +0000 |
commit | 9160cec4c8a0559586d90a6dcf9b2a2551a5fbd8 (patch) | |
tree | 8d219e56835d1e589328276d03c7d495cb2298f7 /testing/fx_string_testhelpers.cpp | |
parent | 8481c71db0e3abed7bd12669116b223a65bebbb4 (diff) | |
download | pdfium-9160cec4c8a0559586d90a6dcf9b2a2551a5fbd8.tar.xz |
Change CFX_BufferSeekableReadStream to take a span.
Change-Id: Ib9e20fdfc637b2ba0358586e23ad72454b0b8ad1
Reviewed-on: https://pdfium-review.googlesource.com/38851
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'testing/fx_string_testhelpers.cpp')
-rw-r--r-- | testing/fx_string_testhelpers.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/testing/fx_string_testhelpers.cpp b/testing/fx_string_testhelpers.cpp index e2ce9353fb..e3c443ac4e 100644 --- a/testing/fx_string_testhelpers.cpp +++ b/testing/fx_string_testhelpers.cpp @@ -24,8 +24,22 @@ CFX_InvalidSeekableReadStream::CFX_InvalidSeekableReadStream( CFX_InvalidSeekableReadStream::~CFX_InvalidSeekableReadStream() = default; CFX_BufferSeekableReadStream::CFX_BufferSeekableReadStream( - const unsigned char* src, - size_t src_size) - : data_(src), data_size_(src_size) {} + pdfium::span<const uint8_t> data) + : data_(data) {} CFX_BufferSeekableReadStream::~CFX_BufferSeekableReadStream() = default; + +bool CFX_BufferSeekableReadStream::ReadBlock(void* buffer, + FX_FILESIZE offset, + size_t size) { + if (offset < 0 || static_cast<size_t>(offset) >= data_.size()) + return false; + + if (static_cast<size_t>(offset) + size > data_.size()) + size = data_.size() - static_cast<size_t>(offset); + if (size == 0) + return false; + + memcpy(buffer, &data_[offset], size); + return true; +} |