Rewrite some pdfium::span usage
Some existing usage of pdfium::span is not compatible with a more modern
span. Rewrite them so they will work once the span implementation gets
updated.
Bug: pdfium:2085
Change-Id: I0eacff20d5d1e246259a75d125faaa0f6616f70b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/112810
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 9a2b88b..ee0b371 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -107,7 +107,8 @@
buffer[3] = FX_Random_MT_Generate(pContext2);
FX_Random_MT_Close(pContext1);
FX_Random_MT_Close(pContext2);
- return ByteString(pdfium::as_bytes<uint32_t>(buffer));
+ return ByteString(
+ ByteStringView(pdfium::as_bytes(pdfium::make_span(buffer))));
}
bool OutputIndex(IFX_ArchiveStream* archive, FX_FILESIZE offset) {
diff --git a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
index 79bf534..544f317 100644
--- a/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_decode_unittest.cpp
@@ -28,7 +28,7 @@
// Converts a string literal into a `uint8_t` span.
template <size_t N>
pdfium::span<const uint8_t> ToSpan(const char (&array)[N]) {
- return pdfium::span(reinterpret_cast<const uint8_t*>(array), N - 1);
+ return pdfium::as_bytes(ByteStringView(array, N - 1).span());
}
// Converts a string literal into a `ByteString`.
diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
index 56318fe..75b3ec1 100644
--- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
@@ -25,7 +25,7 @@
using CFX_GifContext::ReadLogicalScreenDescriptor;
CFX_CodecMemory* InputBuffer() const { return input_buffer_.Get(); }
- void SetTestInputBuffer(pdfium::span<uint8_t> input) {
+ void SetTestInputBuffer(pdfium::span<const uint8_t> input) {
auto pMemory = pdfium::MakeRetain<CFX_CodecMemory>(input.size());
fxcrt::spancpy(pMemory->GetBufferSpan(), input);
SetInputBuffer(std::move(pMemory));
@@ -36,7 +36,7 @@
uint8_t buffer[] = {0x00, 0x01, 0x02};
CFX_GifContextForTest context;
- context.SetTestInputBuffer({nullptr, 0u});
+ context.SetTestInputBuffer({});
EXPECT_EQ(0u, context.InputBuffer()->GetSize());
EXPECT_EQ(0u, context.InputBuffer()->GetPosition());
@@ -55,7 +55,7 @@
0x05, 0x06, 0x07, 0x08, 0x09};
CFX_GifContextForTest context;
- context.SetTestInputBuffer({nullptr, 0u});
+ context.SetTestInputBuffer({});
EXPECT_FALSE(context.ReadAllOrNone(nullptr, 0));
EXPECT_FALSE(context.ReadAllOrNone(nullptr, 10));
diff --git a/core/fxcrt/cfx_seekablestreamproxy_unittest.cpp b/core/fxcrt/cfx_seekablestreamproxy_unittest.cpp
index 05cc492..aee35bc 100644
--- a/core/fxcrt/cfx_seekablestreamproxy_unittest.cpp
+++ b/core/fxcrt/cfx_seekablestreamproxy_unittest.cpp
@@ -14,7 +14,7 @@
TEST(SeekableStreamProxyTest, NullStream) {
auto proxy_stream = pdfium::MakeRetain<CFX_SeekableStreamProxy>(
pdfium::MakeRetain<CFX_ReadOnlySpanStream>(
- pdfium::make_span<const uint8_t>(nullptr, 0)));
+ pdfium::span<const uint8_t>()));
wchar_t buffer[16];
EXPECT_EQ(0u, proxy_stream->ReadBlock(buffer, std::size(buffer)));
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 29c8028..fd5b32d 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -30,7 +30,7 @@
}
TEST(CFX_FloatRect, GetBBox) {
- CFX_FloatRect rect = CFX_FloatRect::GetBBox({nullptr, 0});
+ CFX_FloatRect rect = CFX_FloatRect::GetBBox({});
EXPECT_FLOAT_EQ(0.0f, rect.left);
EXPECT_FLOAT_EQ(0.0f, rect.bottom);
EXPECT_FLOAT_EQ(0.0f, rect.right);