Change CBC_QRCoderBitVector::GetArray() to return a span.
Deal with spans instead of raw pointers.
Bug: pdfium:1706
Change-Id: I83287e7eda7701b99d9497692303e91f7345aec1
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/96413
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
index def9221..cfe232e 100644
--- a/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderBitVector.cpp
@@ -79,14 +79,14 @@
if (m_sizeInBits != other->Size())
return false;
- const auto* pOther = other->GetArray();
+ pdfium::span<const uint8_t> other_span = other->GetArray();
for (size_t i = 0; i < sizeInBytes(); ++i)
- m_array[i] ^= pOther[i];
+ m_array[i] ^= other_span[i];
return true;
}
-const uint8_t* CBC_QRCoderBitVector::GetArray() const {
- return m_array.data();
+pdfium::span<const uint8_t> CBC_QRCoderBitVector::GetArray() const {
+ return m_array;
}
void CBC_QRCoderBitVector::AppendByte(int8_t value) {
diff --git a/fxbarcode/qrcode/BC_QRCoderBitVector.h b/fxbarcode/qrcode/BC_QRCoderBitVector.h
index f2e7e2a..f641e83 100644
--- a/fxbarcode/qrcode/BC_QRCoderBitVector.h
+++ b/fxbarcode/qrcode/BC_QRCoderBitVector.h
@@ -11,13 +11,14 @@
#include <stdint.h>
#include "core/fxcrt/data_vector.h"
+#include "third_party/base/span.h"
class CBC_QRCoderBitVector {
public:
CBC_QRCoderBitVector();
~CBC_QRCoderBitVector();
- const uint8_t* GetArray() const;
+ pdfium::span<const uint8_t> GetArray() const;
int32_t At(size_t index) const;
size_t Size() const;
size_t sizeInBytes() const;
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 46aa0a3..b209fae 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -31,6 +31,7 @@
#include "core/fxcrt/data_vector.h"
#include "core/fxcrt/fx_string.h"
+#include "core/fxcrt/span_util.h"
#include "fxbarcode/common/BC_CommonByteMatrix.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomon.h"
#include "fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
@@ -320,8 +321,9 @@
return false;
DataVector<uint8_t> dataBytes(numDataBytesInBlock);
- memcpy(dataBytes.data(), bits->GetArray() + dataBytesOffset,
- numDataBytesInBlock);
+ fxcrt::spancpy(
+ pdfium::make_span(dataBytes),
+ bits->GetArray().subspan(dataBytesOffset, numDataBytesInBlock));
DataVector<uint8_t> ecBytes = GenerateECBytes(dataBytes, numEcBytesInBlock);
if (ecBytes.empty())
return false;