summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-15 13:51:34 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-15 13:51:34 -0800
commit47fb8c06acd0ff9ea50c8c2d7f67510ea5c28577 (patch)
treeb6c3594bdf3690d00f2fd959f06cef1d45ae0f71 /core/fpdfapi/page
parentb04b96b1ea3ef88385bbf736b2bccab7ed12c486 (diff)
downloadpdfium-47fb8c06acd0ff9ea50c8c2d7f67510ea5c28577.tar.xz
Return unique_ptr from CFX_BinaryBuf::DetachBuffer()
In turn, make CPDF_Stream() take an unique_ptr. Review-Url: https://codereview.chromium.org/2584683002
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp18
2 files changed, 19 insertions, 16 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 97969551c6..a0109f22a8 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -219,8 +219,9 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
pCS->AddNew<CPDF_Name>("Indexed");
pCS->AddNew<CPDF_Name>("DeviceRGB");
pCS->AddNew<CPDF_Number>(iPalette - 1);
- uint8_t* pColorTable = FX_Alloc2D(uint8_t, iPalette, 3);
- uint8_t* ptr = pColorTable;
+ std::unique_ptr<uint8_t, FxFreeDeleter> pColorTable(
+ FX_Alloc2D(uint8_t, iPalette, 3));
+ uint8_t* ptr = pColorTable.get();
for (int32_t i = 0; i < iPalette; i++) {
uint32_t argb = pBitmap->GetPaletteArgb(i);
ptr[0] = (uint8_t)(argb >> 16);
@@ -231,7 +232,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
auto pNewDict =
pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
CPDF_Stream* pCTS = m_pDocument->NewIndirect<CPDF_Stream>(
- pColorTable, iPalette * 3, std::move(pNewDict));
+ std::move(pColorTable), iPalette * 3, std::move(pNewDict));
pCS->AddNew<CPDF_Reference>(m_pDocument, pCTS->GetObjNum());
pDict->SetNewFor<CPDF_Reference>("ColorSpace", m_pDocument,
pCS->GetObjNum());
@@ -254,7 +255,7 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
if (pMaskBitmap) {
int32_t maskWidth = pMaskBitmap->GetWidth();
int32_t maskHeight = pMaskBitmap->GetHeight();
- uint8_t* mask_buf = nullptr;
+ std::unique_ptr<uint8_t, FxFreeDeleter> mask_buf;
FX_STRSIZE mask_size = 0;
auto pMaskDict =
pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
@@ -265,16 +266,16 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
pMaskDict->SetNewFor<CPDF_Name>("ColorSpace", "DeviceGray");
pMaskDict->SetNewFor<CPDF_Number>("BitsPerComponent", 8);
if (pMaskBitmap->GetFormat() != FXDIB_1bppMask) {
- mask_buf = FX_Alloc2D(uint8_t, maskHeight, maskWidth);
+ mask_buf.reset(FX_Alloc2D(uint8_t, maskHeight, maskWidth));
mask_size = maskHeight * maskWidth; // Safe since checked alloc returned.
for (int32_t a = 0; a < maskHeight; a++) {
- FXSYS_memcpy(mask_buf + a * maskWidth, pMaskBitmap->GetScanline(a),
- maskWidth);
+ FXSYS_memcpy(mask_buf.get() + a * maskWidth,
+ pMaskBitmap->GetScanline(a), maskWidth);
}
}
pMaskDict->SetNewFor<CPDF_Number>("Length", mask_size);
CPDF_Stream* pNewStream = m_pDocument->NewIndirect<CPDF_Stream>(
- mask_buf, mask_size, std::move(pMaskDict));
+ std::move(mask_buf), mask_size, std::move(pMaskDict));
pDict->SetNewFor<CPDF_Reference>("SMask", m_pDocument,
pNewStream->GetObjNum());
}
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index fd5267b111..cf87ce9954 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -178,21 +178,22 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
return nullptr;
OrigSize *= height;
- uint8_t* pData = nullptr;
+ std::unique_ptr<uint8_t, FxFreeDeleter> pData;
uint32_t dwStreamSize;
if (Decoder.IsEmpty()) {
if (OrigSize > m_Size - m_Pos)
OrigSize = m_Size - m_Pos;
- pData = FX_Alloc(uint8_t, OrigSize);
- FXSYS_memcpy(pData, m_pBuf + m_Pos, OrigSize);
+ pData.reset(FX_Alloc(uint8_t, OrigSize));
+ FXSYS_memcpy(pData.get(), m_pBuf + m_Pos, OrigSize);
dwStreamSize = OrigSize;
m_Pos += OrigSize;
} else {
+ uint8_t* pIgnore;
uint32_t dwDestSize = OrigSize;
dwStreamSize =
PDF_DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height,
- Decoder, pParam, pData, dwDestSize);
- FX_Free(pData);
+ Decoder, pParam, pIgnore, dwDestSize);
+ FX_Free(pIgnore);
if (static_cast<int>(dwStreamSize) < 0)
return nullptr;
@@ -216,12 +217,13 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
dwStreamSize += m_Pos - dwPrevPos;
}
m_Pos = dwSavePos;
- pData = FX_Alloc(uint8_t, dwStreamSize);
- FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
+ pData.reset(FX_Alloc(uint8_t, dwStreamSize));
+ FXSYS_memcpy(pData.get(), m_pBuf + m_Pos, dwStreamSize);
m_Pos += dwStreamSize;
}
pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
- return pdfium::MakeUnique<CPDF_Stream>(pData, dwStreamSize, std::move(pDict));
+ return pdfium::MakeUnique<CPDF_Stream>(std::move(pData), dwStreamSize,
+ std::move(pDict));
}
CPDF_StreamParser::SyntaxType CPDF_StreamParser::ParseNextElement() {