Use fxcrt::spancpy() in a few more places in fpdfapi parsers.
Change-Id: I18447459a7ce2c1f2a87238ace6c7886db20ec02
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82690
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp
index 9a97a80..87ca911 100644
--- a/core/fpdfapi/edit/cpdf_creator.cpp
+++ b/core/fpdfapi/edit/cpdf_creator.cpp
@@ -24,6 +24,7 @@
#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_random.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "core/fxcrt/span_util.h"
#include "core/fxcrt/stl_util.h"
#include "third_party/base/check.h"
#include "third_party/base/containers/contains.h"
@@ -82,7 +83,8 @@
size_t temp_size = size;
while (temp_size) {
size_t buf_size = std::min(kArchiveBufferSize - current_length_, temp_size);
- memcpy(buffer_.data() + current_length_, buffer, buf_size);
+ fxcrt::spancpy(fxcrt::Subspan(buffer_, current_length_),
+ pdfium::make_span(buffer, buf_size));
current_length_ += buf_size;
if (current_length_ == kArchiveBufferSize && !Flush())
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 823a0fc..912a6ef 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -19,6 +19,7 @@
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/pauseindicator_iface.h"
+#include "core/fxcrt/span_util.h"
#include "core/fxge/cfx_fillrenderoptions.h"
#include "third_party/base/check.h"
#include "third_party/base/check_op.h"
@@ -173,13 +174,13 @@
return Stage::kComplete;
uint32_t pos = 0;
+ auto data_span = pdfium::make_span(m_pData.Get(), m_Size);
for (const auto& stream : m_StreamArray) {
- memcpy(m_pData.Get() + pos, stream->GetData(), stream->GetSize());
+ fxcrt::spancpy(data_span.subspan(pos), stream->GetSpan());
pos += stream->GetSize();
- m_pData.Get()[pos++] = ' ';
+ data_span[pos++] = ' ';
}
m_StreamArray.clear();
-
return Stage::kParse;
}
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 5f32a8b..3a4ef25 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -26,6 +26,7 @@
#include "core/fxcodec/jpeg/jpegmodule.h"
#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/span_util.h"
#include "core/fxge/dib/cfx_dibitmap.h"
#include "core/fxge/dib/fx_dib.h"
#include "third_party/base/check.h"
@@ -290,7 +291,8 @@
size_t dest_span_offset = 0;
if (bCopyWithoutAlpha) {
for (int32_t i = 0; i < BitmapHeight; i++) {
- memcpy(&dest_span[dest_span_offset], src_buf, dest_pitch);
+ fxcrt::spancpy(dest_span.subspan(dest_span_offset),
+ pdfium::make_span(src_buf, dest_pitch));
dest_span_offset += dest_pitch;
src_buf += src_pitch;
}
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index b896cb8..da16168 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -29,6 +29,7 @@
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memory_wrappers.h"
#include "core/fxcrt/fx_safe_types.h"
+#include "core/fxcrt/span_util.h"
#include "third_party/base/check.h"
namespace {
@@ -168,8 +169,8 @@
if (decoder.IsEmpty()) {
dwOrigSize = std::min<uint32_t>(dwOrigSize, m_pBuf.size() - m_Pos);
pData.reset(FX_AllocUninit(uint8_t, dwOrigSize));
- auto copy_span = m_pBuf.subspan(m_Pos, dwOrigSize);
- memcpy(pData.get(), copy_span.data(), copy_span.size());
+ auto dest_span = pdfium::make_span(pData.get(), dwOrigSize);
+ fxcrt::spancpy(dest_span, m_pBuf.subspan(m_Pos, dwOrigSize));
dwStreamSize = dwOrigSize;
m_Pos += dwOrigSize;
} else {
@@ -198,8 +199,8 @@
}
m_Pos = dwSavePos;
pData.reset(FX_AllocUninit(uint8_t, dwStreamSize));
- auto copy_span = m_pBuf.subspan(m_Pos, dwStreamSize);
- memcpy(pData.get(), copy_span.data(), copy_span.size());
+ auto dest_span = pdfium::make_span(pData.get(), dwStreamSize);
+ fxcrt::spancpy(dest_span, m_pBuf.subspan(m_Pos, dwStreamSize));
m_Pos += dwStreamSize;
}
pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(dwStreamSize));
diff --git a/core/fpdfapi/parser/cpdf_seekablemultistream.cpp b/core/fpdfapi/parser/cpdf_seekablemultistream.cpp
index 578db3e..449b2cc 100644
--- a/core/fpdfapi/parser/cpdf_seekablemultistream.cpp
+++ b/core/fpdfapi/parser/cpdf_seekablemultistream.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
+#include "core/fxcrt/span_util.h"
#include "core/fxcrt/stl_util.h"
#include "third_party/base/notreached.h"
@@ -43,16 +44,16 @@
offset -= dwSize;
index++;
}
+ auto buffer_span = pdfium::make_span(static_cast<uint8_t*>(buffer), size);
while (index < iCount) {
- const auto& acc = m_Data[index];
- uint32_t dwSize = acc->GetSize();
- size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset));
- memcpy(buffer, acc->GetSpan().subspan(offset, dwRead).data(), dwRead);
- size -= dwRead;
- if (size == 0)
+ auto acc_span = m_Data[index]->GetSpan();
+ size_t dwRead =
+ std::min<size_t>(buffer_span.size(), acc_span.size() - offset);
+ fxcrt::spancpy(buffer_span, acc_span.subspan(offset, dwRead));
+ buffer_span = buffer_span.subspan(dwRead);
+ if (buffer_span.empty())
return true;
- buffer = static_cast<uint8_t*>(buffer) + dwRead;
offset = 0;
index++;
}