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

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

Issue 2520133002: Remove some WrapUnique() calls by returing unique_ptrs (Closed)
Patch Set: rebase Created 4 years, 1 month 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.h ('k') | core/fpdfapi/page/cpdf_streamcontentparser.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/page/cpdf_image.cpp
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 66599a82683926e8c689ec3fa68cbeb5e760bc8e..dafca2b764c71ff76761f475a90e67c29ae8b774 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -26,6 +26,7 @@
#include "core/fpdfapi/render/render_int.h"
#include "core/fxcodec/fx_codec.h"
#include "core/fxge/fx_dib.h"
+#include "third_party/base/numerics/safe_conversions.h"
#include "third_party/base/ptr_util.h"
CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {}
@@ -86,7 +87,8 @@ void CPDF_Image::ConvertStreamToIndirectObject() {
m_pDocument->AddIndirectObject(std::move(m_pOwnedStream));
}
-CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
+std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData,
+ uint32_t size) {
int32_t width;
int32_t height;
int32_t num_comps;
@@ -97,8 +99,8 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
return nullptr;
}
- CPDF_Dictionary* pDict =
- new CPDF_Dictionary(m_pDocument->GetByteStringPool());
+ auto pDict =
+ pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
pDict->SetNewFor<CPDF_Name>("Type", "XObject");
pDict->SetNewFor<CPDF_Name>("Subtype", "Image");
pDict->SetNewFor<CPDF_Number>("Width", width);
@@ -134,14 +136,17 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
}
void CPDF_Image::SetJpegImage(IFX_SeekableReadStream* pFile) {
- uint32_t size = (uint32_t)pFile->GetSize();
+ uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize());
if (!size)
return;
uint32_t dwEstimateSize = std::min(size, 8192U);
std::vector<uint8_t> data(dwEstimateSize);
- pFile->ReadBlock(data.data(), 0, dwEstimateSize);
- CPDF_Dictionary* pDict = InitJPEG(data.data(), dwEstimateSize);
+ if (!pFile->ReadBlock(data.data(), 0, dwEstimateSize))
+ return;
+
+ std::unique_ptr<CPDF_Dictionary> pDict =
+ InitJPEG(data.data(), dwEstimateSize);
if (!pDict && size > dwEstimateSize) {
data.resize(size);
pFile->ReadBlock(data.data(), 0, size);
@@ -150,7 +155,7 @@ void CPDF_Image::SetJpegImage(IFX_SeekableReadStream* pFile) {
if (!pDict)
return;
- m_pStream->InitStreamFromFile(pFile, pdfium::WrapUnique(pDict));
+ m_pStream->InitStreamFromFile(pFile, std::move(pDict));
}
void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap) {
« no previous file with comments | « core/fpdfapi/page/cpdf_image.h ('k') | core/fpdfapi/page/cpdf_streamcontentparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698