Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5748)

Unified Diff: core/fpdfapi/page/cpdf_streamparser.cpp

Issue 2584683002: Return unique_ptr from CFX_BinaryBuf::DetachBuffer() (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/page/cpdf_image.cpp ('k') | core/fpdfapi/parser/cpdf_object_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/page/cpdf_streamparser.cpp
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index fd5267b111446e21ad8188c0cb7b1edf25790757..cf87ce9954b155c21617b95e0f03e75345095667 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() {
« no previous file with comments | « core/fpdfapi/page/cpdf_image.cpp ('k') | core/fpdfapi/parser/cpdf_object_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698