From 0bb1333a9eff1190ddd68f34c71d6a779c69dfef Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 30 Mar 2017 16:12:02 -0400 Subject: Add some calls to MakeUnique This CL replaces some new's with pdfium::MakeUnique. Change-Id: I50faf3ed55e7730b094c14a7989a9dd51cf33cbb Reviewed-on: https://pdfium-review.googlesource.com/3430 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fpdfapi/font/cpdf_type3font.cpp | 4 +-- core/fpdfapi/page/cpdf_streamcontentparser.cpp | 14 +++++----- core/fpdfapi/parser/cpdf_array_unittest.cpp | 13 ++++----- core/fpdfapi/parser/cpdf_object_unittest.cpp | 19 ++++++------- core/fpdfapi/render/cpdf_dibsource.cpp | 14 ++++++---- core/fpdfdoc/cpdf_filespec_unittest.cpp | 12 ++++---- core/fpdfdoc/cpdf_formfield.cpp | 2 +- core/fxcodec/codec/ccodec_jpxmodule.h | 8 +++--- core/fxcodec/codec/cjpx_decoder.h | 36 ++++++++++++++++++++++++ core/fxcodec/codec/fx_codec_flate.cpp | 4 +-- core/fxcodec/codec/fx_codec_jpx_opj.cpp | 37 +++++++------------------ core/fxcodec/jbig2/JBig2_Context.cpp | 38 ++++++++++++-------------- core/fxcodec/jbig2/JBig2_GrdProc.cpp | 17 ++++++------ core/fxcodec/jbig2/JBig2_GrrdProc.cpp | 9 +++--- core/fxcodec/jbig2/JBig2_GsidProc.cpp | 5 ++-- core/fxcodec/jbig2/JBig2_HtrdProc.cpp | 8 +++--- core/fxcodec/jbig2/JBig2_PddProc.cpp | 9 +++--- core/fxcodec/jbig2/JBig2_TrdProc.cpp | 14 ++++------ core/fxcrt/fx_basic_util.cpp | 9 +++--- core/fxge/android/fx_android_imp.cpp | 3 +- core/fxge/ge/cfx_fontcache.cpp | 3 +- 21 files changed, 150 insertions(+), 128 deletions(-) create mode 100644 core/fxcodec/codec/cjpx_decoder.h (limited to 'core') diff --git a/core/fpdfapi/font/cpdf_type3font.cpp b/core/fpdfapi/font/cpdf_type3font.cpp index b9a05a0588..59702aed6a 100644 --- a/core/fpdfapi/font/cpdf_type3font.cpp +++ b/core/fpdfapi/font/cpdf_type3font.cpp @@ -105,9 +105,9 @@ CPDF_Type3Char* CPDF_Type3Font::LoadChar(uint32_t charcode) { if (!pStream) return nullptr; - std::unique_ptr pNewChar(new CPDF_Type3Char(new CPDF_Form( + auto pNewChar = pdfium::MakeUnique(new CPDF_Form( m_pDocument, m_pFontResources ? m_pFontResources : m_pPageResources, - pStream, nullptr))); + pStream, nullptr)); // This can trigger recursion into this method. The content of |m_CacheMap| // can change as a result. Thus after it returns, check the cache again for diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp index 312996ba11..4c64e13b06 100644 --- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp +++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp @@ -262,7 +262,7 @@ CPDF_StreamContentParser::CPDF_StreamContentParser( m_Level(level), m_ParamStartPos(0), m_ParamCount(0), - m_pCurStates(new CPDF_AllStates), + m_pCurStates(pdfium::MakeUnique()), m_pLastTextObject(nullptr), m_DefFontSize(0), m_PathStartX(0.0f), @@ -765,9 +765,9 @@ void CPDF_StreamContentParser::Handle_ExecuteXObject() { } void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { - std::unique_ptr pFormObj(new CPDF_FormObject); - pFormObj->m_pForm.reset( - new CPDF_Form(m_pDocument, m_pPageResources, pStream, m_pResources)); + auto pFormObj = pdfium::MakeUnique(); + pFormObj->m_pForm = pdfium::MakeUnique( + m_pDocument, m_pPageResources, pStream, m_pResources); pFormObj->m_FormMatrix = m_pCurStates->m_CTM; pFormObj->m_FormMatrix.Concat(m_mtContentToUser); CPDF_AllStates status; @@ -957,7 +957,7 @@ void CPDF_StreamContentParser::Handle_EndPath() { } void CPDF_StreamContentParser::Handle_SaveGraphState() { - std::unique_ptr pStates(new CPDF_AllStates); + auto pStates = pdfium::MakeUnique(); pStates->Copy(*m_pCurStates); m_StateStack.push_back(std::move(pStates)); } @@ -1110,7 +1110,7 @@ void CPDF_StreamContentParser::Handle_ShadeFill() { if (!pShading->IsShadingObject() || !pShading->Load()) return; - std::unique_ptr pObj(new CPDF_ShadingObject); + auto pObj = pdfium::MakeUnique(); pObj->m_pShading = pShading; SetGraphicStates(pObj.get(), false, false, false); pObj->m_Matrix = m_pCurStates->m_CTM; @@ -1248,7 +1248,7 @@ void CPDF_StreamContentParser::AddTextObject(CFX_ByteString* pStrs, pFont->IsType3Font() ? TextRenderingMode::MODE_FILL : m_pCurStates->m_TextState.GetTextMode(); { - std::unique_ptr pText(new CPDF_TextObject); + auto pText = pdfium::MakeUnique(); m_pLastTextObject = pText.get(); SetGraphicStates(m_pLastTextObject, true, true, true); if (TextRenderingModeIsStrokeMode(text_mode)) { diff --git a/core/fpdfapi/parser/cpdf_array_unittest.cpp b/core/fpdfapi/parser/cpdf_array_unittest.cpp index 6d458d83cd..1e92b32716 100644 --- a/core/fpdfapi/parser/cpdf_array_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_array_unittest.cpp @@ -15,7 +15,7 @@ TEST(cpdf_array, RemoveAt) { { int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - std::unique_ptr arr(new CPDF_Array); + auto arr = pdfium::MakeUnique(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddNew(elems[i]); arr->RemoveAt(3, 3); @@ -32,7 +32,7 @@ TEST(cpdf_array, RemoveAt) { { // When the range is out of bound, RemoveAt has no effect. int elems[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - std::unique_ptr arr(new CPDF_Array); + auto arr = pdfium::MakeUnique(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->AddNew(elems[i]); arr->RemoveAt(8, 5); @@ -102,14 +102,13 @@ TEST(cpdf_array, Clone) { static const size_t kNumOfRowElems = 5; int elems[kNumOfRows][kNumOfRowElems] = { {1, 2, 3, 4, 5}, {10, 9, 8, 7, 6}, {11, 12, 13, 14, 15}}; - std::unique_ptr arr(new CPDF_Array); + auto arr = pdfium::MakeUnique(); // Indirect references to indirect objects. - std::unique_ptr obj_holder( - new CPDF_IndirectObjectHolder()); + auto obj_holder = pdfium::MakeUnique(); for (size_t i = 0; i < kNumOfRows; ++i) { auto arr_elem = pdfium::MakeUnique(); for (size_t j = 0; j < kNumOfRowElems; ++j) { - std::unique_ptr obj(new CPDF_Number(elems[i][j])); + auto obj = pdfium::MakeUnique(elems[i][j]); // Starts object number from 1. int obj_num = i * kNumOfRowElems + j + 1; obj_holder->ReplaceIndirectObjectIfHigherGeneration(obj_num, @@ -168,7 +167,7 @@ TEST(cpdf_array, Clone) { TEST(cpdf_array, Iterator) { const int elems[] = {-23, -11, 3, 455, 2345877, 0, 7895330, -12564334, 10000, -100000}; - std::unique_ptr arr(new CPDF_Array); + auto arr = pdfium::MakeUnique(); for (size_t i = 0; i < FX_ArraySize(elems); ++i) arr->InsertNewAt(i, elems[i]); size_t index = 0; diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index b25d40a029..3b5374b637 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -484,8 +484,8 @@ TEST(PDFArrayTest, GetTypeAt) { // String and name array const char* const vals[] = {"this", "adsde$%^", "\r\t", "\"012", ".", "EYREW", "It is a joke :)"}; - std::unique_ptr string_array(new CPDF_Array); - std::unique_ptr name_array(new CPDF_Array); + auto string_array = pdfium::MakeUnique(); + auto name_array = pdfium::MakeUnique(); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { string_array->InsertNewAt(i, vals[i], false); name_array->InsertNewAt(i, vals[i]); @@ -695,8 +695,8 @@ TEST(PDFArrayTest, AddInteger) { TEST(PDFArrayTest, AddStringAndName) { const char* vals[] = {"", "a", "ehjhRIOYTTFdfcdnv", "122323", "$#%^&**", " ", "This is a test.\r\n"}; - std::unique_ptr string_array(new CPDF_Array); - std::unique_ptr name_array(new CPDF_Array); + auto string_array = pdfium::MakeUnique(); + auto name_array = pdfium::MakeUnique(); for (size_t i = 0; i < FX_ArraySize(vals); ++i) { string_array->AddNew(vals[i], false); name_array->AddNew(vals[i]); @@ -710,8 +710,7 @@ TEST(PDFArrayTest, AddStringAndName) { } TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { - std::unique_ptr holder( - new CPDF_IndirectObjectHolder()); + auto holder = pdfium::MakeUnique(); CPDF_Boolean* boolean_obj = new CPDF_Boolean(true); CPDF_Number* int_obj = new CPDF_Number(-1234); CPDF_Number* float_obj = new CPDF_Number(2345.089f); @@ -723,7 +722,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { str_obj, name_obj, null_obj}; unsigned int obj_nums[] = {2, 4, 7, 2345, 799887, 1}; auto arr = pdfium::MakeUnique(); - std::unique_ptr arr1(new CPDF_Array); + auto arr1 = pdfium::MakeUnique(); // Create two arrays of references by different AddReference() APIs. for (size_t i = 0; i < FX_ArraySize(indirect_objs); ++i) { holder->ReplaceIndirectObjectIfHigherGeneration( @@ -748,7 +747,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) { TEST(PDFArrayTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; - std::unique_ptr array(new CPDF_Array); + auto array = pdfium::MakeUnique(); array->AddNew(&objects_holder, 1234); ASSERT_EQ(1U, array->GetCount()); CPDF_Object* obj = array->GetObjectAt(0); @@ -782,7 +781,7 @@ TEST(PDFArrayTest, ConvertIndirect) { TEST(PDFDictionaryTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; - std::unique_ptr dict(new CPDF_Dictionary()); + auto dict = pdfium::MakeUnique(); dict->SetNewFor("foo", &objects_holder, 1234); ASSERT_EQ(1U, dict->GetCount()); CPDF_Object* obj = dict->GetObjectFor("foo"); @@ -867,7 +866,7 @@ TEST(PDFObjectTest, CloneCheckLoop) { TEST(PDFDictionaryTest, ConvertIndirect) { CPDF_IndirectObjectHolder objects_holder; - std::unique_ptr dict(new CPDF_Dictionary); + auto dict = pdfium::MakeUnique(); CPDF_Object* pObj = dict->SetNewFor("clams", 42); dict->ConvertToIndirectObjectFor("clams", &objects_holder); CPDF_Object* pRef = dict->GetObjectFor("clams"); diff --git a/core/fpdfapi/render/cpdf_dibsource.cpp b/core/fpdfapi/render/cpdf_dibsource.cpp index f3703dd23a..cb8e9c9eee 100644 --- a/core/fpdfapi/render/cpdf_dibsource.cpp +++ b/core/fpdfapi/render/cpdf_dibsource.cpp @@ -21,6 +21,7 @@ #include "core/fpdfapi/parser/fpdf_parser_decode.h" #include "core/fpdfapi/render/cpdf_pagerendercache.h" #include "core/fpdfapi/render/cpdf_renderstatus.h" +#include "core/fxcodec/codec/cjpx_decoder.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/ptr_util.h" @@ -79,16 +80,17 @@ class JpxBitMapContext { explicit JpxBitMapContext(CCodec_JpxModule* jpx_module) : jpx_module_(jpx_module), decoder_(nullptr) {} - ~JpxBitMapContext() { jpx_module_->DestroyDecoder(decoder_); } + ~JpxBitMapContext() {} - // Takes ownership of |decoder|. - void set_decoder(CJPX_Decoder* decoder) { decoder_ = decoder; } + void set_decoder(std::unique_ptr decoder) { + decoder_ = std::move(decoder); + } - CJPX_Decoder* decoder() { return decoder_; } + CJPX_Decoder* decoder() { return decoder_.get(); } private: CCodec_JpxModule* const jpx_module_; // Weak pointer. - CJPX_Decoder* decoder_; // Decoder, owned. + std::unique_ptr decoder_; // Disallow evil constructors JpxBitMapContext(const JpxBitMapContext&); @@ -613,7 +615,7 @@ void CPDF_DIBSource::LoadJpxBitmap() { if (!pJpxModule) return; - std::unique_ptr context(new JpxBitMapContext(pJpxModule)); + auto context = pdfium::MakeUnique(pJpxModule); context->set_decoder(pJpxModule->CreateDecoder( m_pStreamAcc->GetData(), m_pStreamAcc->GetSize(), m_pColorSpace)); if (!context->decoder()) diff --git a/core/fpdfdoc/cpdf_filespec_unittest.cpp b/core/fpdfdoc/cpdf_filespec_unittest.cpp index d164165f00..e237aa5b6b 100644 --- a/core/fpdfdoc/cpdf_filespec_unittest.cpp +++ b/core/fpdfdoc/cpdf_filespec_unittest.cpp @@ -11,6 +11,7 @@ #include "core/fpdfdoc/cpdf_filespec.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" +#include "third_party/base/ptr_util.h" TEST(cpdf_filespec, EncodeDecodeFileName) { std::vector test_data = { @@ -67,8 +68,7 @@ TEST(cpdf_filespec, GetFileName) { L"/docs/test.pdf" #endif }; - std::unique_ptr str_obj( - new CPDF_String(nullptr, test_data.input)); + auto str_obj = pdfium::MakeUnique(nullptr, test_data.input); CPDF_FileSpec file_spec(str_obj.get()); CFX_WideString file_name; EXPECT_TRUE(file_spec.GetFileName(&file_name)); @@ -99,7 +99,7 @@ TEST(cpdf_filespec, GetFileName) { }; // Keyword fields in reverse order of precedence to retrieve the file name. const char* const keywords[5] = {"Unix", "Mac", "DOS", "F", "UF"}; - std::unique_ptr dict_obj(new CPDF_Dictionary()); + auto dict_obj = pdfium::MakeUnique(); CPDF_FileSpec file_spec(dict_obj.get()); CFX_WideString file_name; for (int i = 0; i < 5; ++i) { @@ -116,7 +116,7 @@ TEST(cpdf_filespec, GetFileName) { } { // Invalid object. - std::unique_ptr name_obj(new CPDF_Name(nullptr, "test.pdf")); + auto name_obj = pdfium::MakeUnique(nullptr, "test.pdf"); CPDF_FileSpec file_spec(name_obj.get()); CFX_WideString file_name; EXPECT_FALSE(file_spec.GetFileName(&file_name)); @@ -137,7 +137,7 @@ TEST(cpdf_filespec, SetFileName) { #endif }; // String object. - std::unique_ptr str_obj(new CPDF_String(nullptr, L"babababa")); + auto str_obj = pdfium::MakeUnique(nullptr, L"babababa"); CPDF_FileSpec file_spec1(str_obj.get()); file_spec1.SetFileName(test_data.input); // Check internal object value. @@ -149,7 +149,7 @@ TEST(cpdf_filespec, SetFileName) { EXPECT_TRUE(file_name == test_data.input); // Dictionary object. - std::unique_ptr dict_obj(new CPDF_Dictionary()); + auto dict_obj = pdfium::MakeUnique(); CPDF_FileSpec file_spec2(dict_obj.get()); file_spec2.SetFileName(test_data.input); // Check internal object value. diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index c697cbbf16..e7ca7c6a8d 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -566,7 +566,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) { if (pValue->GetUnicodeText() == opt_value) m_pDict->RemoveFor("V"); } else if (pValue->IsArray()) { - std::unique_ptr pArray(new CPDF_Array); + auto pArray = pdfium::MakeUnique(); for (int i = 0; i < CountOptions(); i++) { if (i != index && IsItemSelected(i)) { opt_value = GetOptionValue(i); diff --git a/core/fxcodec/codec/ccodec_jpxmodule.h b/core/fxcodec/codec/ccodec_jpxmodule.h index fd919d91b0..c57002722e 100644 --- a/core/fxcodec/codec/ccodec_jpxmodule.h +++ b/core/fxcodec/codec/ccodec_jpxmodule.h @@ -7,6 +7,7 @@ #ifndef CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_ #define CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_ +#include #include #include "core/fxcrt/fx_system.h" @@ -19,9 +20,9 @@ class CCodec_JpxModule { CCodec_JpxModule(); ~CCodec_JpxModule(); - CJPX_Decoder* CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - CPDF_ColorSpace* cs); + std::unique_ptr CreateDecoder(const uint8_t* src_buf, + uint32_t src_size, + CPDF_ColorSpace* cs); void GetImageInfo(CJPX_Decoder* pDecoder, uint32_t* width, uint32_t* height, @@ -30,7 +31,6 @@ class CCodec_JpxModule { uint8_t* dest_data, int pitch, const std::vector& offsets); - void DestroyDecoder(CJPX_Decoder* pDecoder); }; #endif // CORE_FXCODEC_CODEC_CCODEC_JPXMODULE_H_ diff --git a/core/fxcodec/codec/cjpx_decoder.h b/core/fxcodec/codec/cjpx_decoder.h new file mode 100644 index 0000000000..2e63caac73 --- /dev/null +++ b/core/fxcodec/codec/cjpx_decoder.h @@ -0,0 +1,36 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FXCODEC_CODEC_CJPX_DECODER_H_ +#define CORE_FXCODEC_CODEC_CJPX_DECODER_H_ + +#include + +#include "third_party/libopenjpeg20/openjpeg.h" + +class CPDF_ColorSpace; + +class CJPX_Decoder { + public: + explicit CJPX_Decoder(CPDF_ColorSpace* cs); + ~CJPX_Decoder(); + + bool Init(const unsigned char* src_data, uint32_t src_size); + void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components); + bool Decode(uint8_t* dest_buf, + int pitch, + const std::vector& offsets); + + private: + const uint8_t* m_SrcData; + uint32_t m_SrcSize; + opj_image_t* image; + opj_codec_t* l_codec; + opj_stream_t* l_stream; + const CPDF_ColorSpace* const m_ColorSpace; +}; + +#endif // CORE_FXCODEC_CODEC_CJPX_DECODER_H_ diff --git a/core/fxcodec/codec/fx_codec_flate.cpp b/core/fxcodec/codec/fx_codec_flate.cpp index 7c19d335bb..269bf58813 100644 --- a/core/fxcodec/codec/fx_codec_flate.cpp +++ b/core/fxcodec/codec/fx_codec_flate.cpp @@ -822,7 +822,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, } if (bLZW) { { - std::unique_ptr decoder(new CLZWDecoder); + auto decoder = pdfium::MakeUnique(); dest_size = 0xFFFFFFFF; offset = src_size; int err = @@ -832,7 +832,7 @@ uint32_t CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, } } { - std::unique_ptr decoder(new CLZWDecoder); + auto decoder = pdfium::MakeUnique(); dest_buf = FX_Alloc(uint8_t, dest_size + 1); dest_buf[dest_size] = '\0'; decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); diff --git a/core/fxcodec/codec/fx_codec_jpx_opj.cpp b/core/fxcodec/codec/fx_codec_jpx_opj.cpp index eccf876218..4fc3d689f1 100644 --- a/core/fxcodec/codec/fx_codec_jpx_opj.cpp +++ b/core/fxcodec/codec/fx_codec_jpx_opj.cpp @@ -7,12 +7,15 @@ #include #include #include +#include #include #include "core/fpdfapi/page/cpdf_colorspace.h" +#include "core/fxcodec/codec/cjpx_decoder.h" #include "core/fxcodec/codec/codec_int.h" #include "core/fxcodec/fx_codec.h" #include "core/fxcrt/fx_safe_types.h" +#include "third_party/base/ptr_util.h" #include "third_party/lcms2-2.6/include/lcms2.h" #include "third_party/libopenjpeg20/openjpeg.h" @@ -669,24 +672,6 @@ void color_apply_conversion(opj_image_t* image) { return; } } -class CJPX_Decoder { - public: - explicit CJPX_Decoder(CPDF_ColorSpace* cs); - ~CJPX_Decoder(); - bool Init(const unsigned char* src_data, uint32_t src_size); - void GetInfo(uint32_t* width, uint32_t* height, uint32_t* components); - bool Decode(uint8_t* dest_buf, - int pitch, - const std::vector& offsets); - - private: - const uint8_t* m_SrcData; - uint32_t m_SrcSize; - opj_image_t* image; - opj_codec_t* l_codec; - opj_stream_t* l_stream; - const CPDF_ColorSpace* const m_ColorSpace; -}; CJPX_Decoder::CJPX_Decoder(CPDF_ColorSpace* cs) : image(nullptr), l_codec(nullptr), l_stream(nullptr), m_ColorSpace(cs) {} @@ -872,13 +857,15 @@ bool CJPX_Decoder::Decode(uint8_t* dest_buf, } CCodec_JpxModule::CCodec_JpxModule() {} + CCodec_JpxModule::~CCodec_JpxModule() {} -CJPX_Decoder* CCodec_JpxModule::CreateDecoder(const uint8_t* src_buf, - uint32_t src_size, - CPDF_ColorSpace* cs) { - std::unique_ptr decoder(new CJPX_Decoder(cs)); - return decoder->Init(src_buf, src_size) ? decoder.release() : nullptr; +std::unique_ptr CCodec_JpxModule::CreateDecoder( + const uint8_t* src_buf, + uint32_t src_size, + CPDF_ColorSpace* cs) { + auto decoder = pdfium::MakeUnique(cs); + return decoder->Init(src_buf, src_size) ? std::move(decoder) : nullptr; } void CCodec_JpxModule::GetImageInfo(CJPX_Decoder* pDecoder, @@ -894,7 +881,3 @@ bool CCodec_JpxModule::Decode(CJPX_Decoder* pDecoder, const std::vector& offsets) { return pDecoder->Decode(dest_data, pitch, offsets); } - -void CCodec_JpxModule::DestroyDecoder(CJPX_Decoder* pDecoder) { - delete pDecoder; -} diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp index 109013204e..9261d16bfc 100644 --- a/core/fxcodec/jbig2/JBig2_Context.cpp +++ b/core/fxcodec/jbig2/JBig2_Context.cpp @@ -122,7 +122,7 @@ int32_t CJBig2_Context::decode_EmbedOrgnazation(IFX_Pause* pPause) { int32_t CJBig2_Context::decode_RandomOrgnazation_FirstPage(IFX_Pause* pPause) { int32_t nRet; while (m_pStream->getByteLeft() > JBIG2_MIN_SEGMENT_SIZE) { - std::unique_ptr pSegment(new CJBig2_Segment); + auto pSegment = pdfium::MakeUnique(); nRet = parseSegmentHeader(pSegment.get()); if (nRet != JBIG2_SUCCESS) { return nRet; @@ -364,7 +364,7 @@ int32_t CJBig2_Context::ProcessingParseSegmentData(CJBig2_Segment* pSegment, return parseGenericRefinementRegion(pSegment); case 48: { uint16_t wTemp; - std::unique_ptr pPageInfo(new JBig2PageInfo); + auto pPageInfo = pdfium::MakeUnique(); if (m_pStream->readInteger(&pPageInfo->m_dwWidth) != 0 || m_pStream->readInteger(&pPageInfo->m_dwHeight) != 0 || m_pStream->readInteger(&pPageInfo->m_dwResolutionX) != 0 || @@ -424,7 +424,7 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, if (m_pStream->readShortInteger(&wFlags) != 0) return JBIG2_ERROR_TOO_SHORT; - std::unique_ptr pSymbolDictDecoder(new CJBig2_SDDProc); + auto pSymbolDictDecoder = pdfium::MakeUnique(); pSymbolDictDecoder->SDHUFF = wFlags & 0x0001; pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001; pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003; @@ -600,8 +600,8 @@ int32_t CJBig2_Context::parseSymbolDict(CJBig2_Segment* pSegment, } if (!cache_hit) { if (bUseGbContext) { - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique(m_pStream.get()); pSegment->m_Result.sd = pSymbolDictDecoder->decode_Arith( pArithDecoder.get(), &gbContext, &grContext); if (!pSegment->m_Result.sd) @@ -644,7 +644,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { return JBIG2_ERROR_TOO_SHORT; } - std::unique_ptr pTRD(new CJBig2_TRDProc); + auto pTRD = pdfium::MakeUnique(); pTRD->SBW = ri.width; pTRD->SBH = ri.height; pTRD->SBHUFF = wFlags & 0x0001; @@ -902,8 +902,8 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); } if (pTRD->SBHUFF == 0) { - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; pSegment->m_Result.im = pTRD->decode_Arith(pArithDecoder.get(), grContext.get(), nullptr); @@ -938,7 +938,7 @@ int32_t CJBig2_Context::parseTextRegion(CJBig2_Segment* pSegment) { int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, IFX_Pause* pPause) { uint8_t cFlags; - std::unique_ptr pPDD(new CJBig2_PDDProc); + auto pPDD = pdfium::MakeUnique(); if (m_pStream->read1Byte(&cFlags) != 0 || m_pStream->read1Byte(&pPDD->HDPW) != 0 || m_pStream->read1Byte(&pPDD->HDPH) != 0 || @@ -956,8 +956,8 @@ int32_t CJBig2_Context::parsePatternDict(CJBig2_Segment* pSegment, std::unique_ptr gbContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique(m_pStream.get()); pSegment->m_Result.pd = pPDD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); if (!pSegment->m_Result.pd) @@ -978,7 +978,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause) { uint8_t cFlags; JBig2RegionInfo ri; - std::unique_ptr pHRD(new CJBig2_HTRDProc); + auto pHRD = pdfium::MakeUnique(); if (parseRegionInfo(&ri) != JBIG2_SUCCESS || m_pStream->read1Byte(&cFlags) != 0 || m_pStream->readInteger(&pHRD->HGW) != 0 || @@ -1022,8 +1022,8 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, std::unique_ptr gbContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(gbContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = + pdfium::MakeUnique(m_pStream.get()); pSegment->m_Result.im = pHRD->decode_Arith(pArithDecoder.get(), gbContext.get(), pPause); if (!pSegment->m_Result.im) @@ -1056,7 +1056,7 @@ int32_t CJBig2_Context::parseHalftoneRegion(CJBig2_Segment* pSegment, int32_t CJBig2_Context::parseGenericRegion(CJBig2_Segment* pSegment, IFX_Pause* pPause) { if (!m_pGRD) { - std::unique_ptr pGRD(new CJBig2_GRDProc); + auto pGRD = pdfium::MakeUnique(); uint8_t cFlags; if (parseRegionInfo(&m_ri) != JBIG2_SUCCESS || m_pStream->read1Byte(&cFlags) != 0) { @@ -1165,7 +1165,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { m_pStream->read1Byte(&cFlags) != 0) { return JBIG2_ERROR_TOO_SHORT; } - std::unique_ptr pGRRD(new CJBig2_GRRDProc); + auto pGRRD = pdfium::MakeUnique(); pGRRD->GRW = ri.width; pGRRD->GRH = ri.height; pGRRD->GRTEMPLATE = !!(cFlags & 0x01); @@ -1202,8 +1202,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { std::unique_ptr grContext( FX_Alloc(JBig2ArithCtx, size)); JBIG2_memset(grContext.get(), 0, sizeof(JBig2ArithCtx) * size); - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(m_pStream.get())); + auto pArithDecoder = pdfium::MakeUnique(m_pStream.get()); pSegment->m_nResultType = JBIG2_IMAGE_POINTER; pSegment->m_Result.im = pGRRD->decode(pArithDecoder.get(), grContext.get()); if (!pSegment->m_Result.im) @@ -1230,8 +1229,7 @@ int32_t CJBig2_Context::parseGenericRefinementRegion(CJBig2_Segment* pSegment) { int32_t CJBig2_Context::parseTable(CJBig2_Segment* pSegment) { pSegment->m_nResultType = JBIG2_HUFFMAN_TABLE_POINTER; pSegment->m_Result.ht = nullptr; - std::unique_ptr pHuff( - new CJBig2_HuffmanTable(m_pStream.get())); + auto pHuff = pdfium::MakeUnique(m_pStream.get()); if (!pHuff->IsOK()) return JBIG2_ERROR_FATAL; diff --git a/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrdProc.cpp index d5d4c6d0dc..675de9bcdd 100644 --- a/core/fxcodec/jbig2/JBig2_GrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrdProc.cpp @@ -12,6 +12,7 @@ #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" #include "core/fxcodec/jbig2/JBig2_BitStream.h" #include "core/fxcodec/jbig2/JBig2_Image.h" +#include "third_party/base/ptr_util.h" CJBig2_GRDProc::CJBig2_GRDProc() : m_loopIndex(0), @@ -65,7 +66,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -164,7 +165,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -214,7 +215,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -312,7 +313,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -360,7 +361,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -458,7 +459,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { @@ -504,7 +505,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt( CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); if (!GBREG->m_pData) return nullptr; @@ -590,7 +591,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext) { int LTP = 0; - std::unique_ptr GBREG(new CJBig2_Image(GBW, GBH)); + auto GBREG = pdfium::MakeUnique(GBW, GBH); GBREG->fill(0); for (uint32_t h = 0; h < GBH; h++) { if (TPGDON) { diff --git a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp index 669fed68e9..936b851d37 100644 --- a/core/fxcodec/jbig2/JBig2_GrrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GrrdProc.cpp @@ -11,6 +11,7 @@ #include "core/fxcodec/jbig2/JBig2_ArithDecoder.h" #include "core/fxcodec/jbig2/JBig2_BitStream.h" #include "core/fxcodec/jbig2/JBig2_Image.h" +#include "third_party/base/ptr_util.h" CJBig2_Image* CJBig2_GRRDProc::decode(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { @@ -35,7 +36,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; - std::unique_ptr GRREG(new CJBig2_Image(GRW, GRH)); + auto GRREG = pdfium::MakeUnique(GRW, GRH); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { if (TPGRON) @@ -155,7 +156,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template0_opt( int32_t iGRW = static_cast(GRW); int32_t iGRH = static_cast(GRH); - std::unique_ptr GRREG(new CJBig2_Image(iGRW, iGRH)); + auto GRREG = pdfium::MakeUnique(iGRW, iGRH); if (!GRREG->m_pData) return nullptr; @@ -283,7 +284,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_unopt( CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* grContext) { int LTP = 0; - std::unique_ptr GRREG(new CJBig2_Image(GRW, GRH)); + auto GRREG = pdfium::MakeUnique(GRW, GRH); GRREG->fill(0); for (uint32_t h = 0; h < GRH; h++) { if (TPGRON) @@ -389,7 +390,7 @@ CJBig2_Image* CJBig2_GRRDProc::decode_Template1_opt( int32_t iGRW = static_cast(GRW); int32_t iGRH = static_cast(GRH); - std::unique_ptr GRREG(new CJBig2_Image(iGRW, iGRH)); + auto GRREG = pdfium::MakeUnique(iGRW, iGRH); if (!GRREG->m_pData) return nullptr; diff --git a/core/fxcodec/jbig2/JBig2_GsidProc.cpp b/core/fxcodec/jbig2/JBig2_GsidProc.cpp index 387f8ee511..e65b47de62 100644 --- a/core/fxcodec/jbig2/JBig2_GsidProc.cpp +++ b/core/fxcodec/jbig2/JBig2_GsidProc.cpp @@ -13,11 +13,12 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcrt/fx_basic.h" +#include "third_party/base/ptr_util.h" uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, JBig2ArithCtx* gbContext, IFX_Pause* pPause) { - std::unique_ptr pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique(); pGRD->MMR = GSMMR; pGRD->GBW = GSW; pGRD->GBH = GSH; @@ -69,7 +70,7 @@ uint32_t* CJBig2_GSIDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, uint32_t* CJBig2_GSIDProc::decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause) { - std::unique_ptr pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique(); pGRD->MMR = GSMMR; pGRD->GBW = GSW; pGRD->GBH = GSH; diff --git a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp index 121bf1d6df..8899fb1350 100644 --- a/core/fxcodec/jbig2/JBig2_HtrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_HtrdProc.cpp @@ -20,7 +20,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, uint32_t HBPP; uint32_t* GI; std::unique_ptr HSKIP; - std::unique_ptr HTREG(new CJBig2_Image(HBW, HBH)); + auto HTREG = pdfium::MakeUnique(HBW, HBH); HTREG->fill(HDEFPIXEL); if (HENABLESKIP == 1) { HSKIP = pdfium::MakeUnique(HGW, HGH); @@ -41,7 +41,7 @@ CJBig2_Image* CJBig2_HTRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, while ((uint32_t)(1 << HBPP) < HNUMPATS) { HBPP++; } - std::unique_ptr pGID(new CJBig2_GSIDProc()); + auto pGID = pdfium::MakeUnique(); pGID->GSMMR = HMMR; pGID->GSW = HGW; pGID->GSH = HGH; @@ -73,13 +73,13 @@ CJBig2_Image* CJBig2_HTRDProc::decode_MMR(CJBig2_BitStream* pStream, uint32_t ng, mg; int32_t x, y; uint32_t* GI; - std::unique_ptr HTREG(new CJBig2_Image(HBW, HBH)); + auto HTREG = pdfium::MakeUnique(HBW, HBH); HTREG->fill(HDEFPIXEL); uint32_t HBPP = 1; while ((uint32_t)(1 << HBPP) < HNUMPATS) { HBPP++; } - std::unique_ptr pGID(new CJBig2_GSIDProc()); + auto pGID = pdfium::MakeUnique(); pGID->GSMMR = HMMR; pGID->GSW = HGW; pGID->GSH = HGH; diff --git a/core/fxcodec/jbig2/JBig2_PddProc.cpp b/core/fxcodec/jbig2/JBig2_PddProc.cpp index 679a87a036..3eef302baf 100644 --- a/core/fxcodec/jbig2/JBig2_PddProc.cpp +++ b/core/fxcodec/jbig2/JBig2_PddProc.cpp @@ -11,6 +11,7 @@ #include "core/fxcodec/jbig2/JBig2_GrdProc.h" #include "core/fxcodec/jbig2/JBig2_Image.h" #include "core/fxcodec/jbig2/JBig2_PatternDict.h" +#include "third_party/base/ptr_util.h" CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( CJBig2_ArithDecoder* pArithDecoder, @@ -18,12 +19,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_Arith( IFX_Pause* pPause) { uint32_t GRAY; CJBig2_Image* BHDC = nullptr; - std::unique_ptr pDict(new CJBig2_PatternDict()); + auto pDict = pdfium::MakeUnique(); pDict->NUMPATS = GRAYMAX + 1; pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); - std::unique_ptr pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique(); pGRD->MMR = HDMMR; pGRD->GBW = (GRAYMAX + 1) * HDPW; pGRD->GBH = HDPH; @@ -60,12 +61,12 @@ CJBig2_PatternDict* CJBig2_PDDProc::decode_MMR(CJBig2_BitStream* pStream, IFX_Pause* pPause) { uint32_t GRAY; CJBig2_Image* BHDC = nullptr; - std::unique_ptr pDict(new CJBig2_PatternDict()); + auto pDict = pdfium::MakeUnique(); pDict->NUMPATS = GRAYMAX + 1; pDict->HDPATS = FX_Alloc(CJBig2_Image*, pDict->NUMPATS); JBIG2_memset(pDict->HDPATS, 0, sizeof(CJBig2_Image*) * pDict->NUMPATS); - std::unique_ptr pGRD(new CJBig2_GRDProc()); + auto pGRD = pdfium::MakeUnique(); pGRD->MMR = HDMMR; pGRD->GBW = (GRAYMAX + 1) * HDPW; pGRD->GBH = HDPH; diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp index 84042dbd8c..cf58d9c3c6 100644 --- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp +++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp @@ -16,9 +16,8 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, JBig2ArithCtx* grContext) { - std::unique_ptr pHuffmanDecoder( - new CJBig2_HuffmanDecoder(pStream)); - std::unique_ptr SBREG(new CJBig2_Image(SBW, SBH)); + auto pHuffmanDecoder = pdfium::MakeUnique(pStream); + auto SBREG = pdfium::MakeUnique(SBW, SBH); SBREG->fill(SBDEFPIXEL); int32_t STRIPT; if (pHuffmanDecoder->decodeAValue(SBHUFFDT, &STRIPT) != 0) @@ -120,7 +119,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; - std::unique_ptr pGRRD(new CJBig2_GRRDProc()); + auto pGRRD = pdfium::MakeUnique(); pGRRD->GRW = WOI + RDWI; pGRRD->GRH = HOI + RDHI; pGRRD->GRTEMPLATE = SBRTEMPLATE; @@ -134,8 +133,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Huffman(CJBig2_BitStream* pStream, pGRRD->GRAT[3] = SBRAT[3]; { - std::unique_ptr pArithDecoder( - new CJBig2_ArithDecoder(pStream)); + auto pArithDecoder = pdfium::MakeUnique(pStream); IBI = pGRRD->decode(pArithDecoder.get(), grContext); if (!IBI) return nullptr; @@ -264,7 +262,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, pIARDY = IARDY.get(); pIAID = IAID.get(); } - std::unique_ptr SBREG(new CJBig2_Image(SBW, SBH)); + auto SBREG = pdfium::MakeUnique(SBW, SBH); SBREG->fill(SBDEFPIXEL); int32_t STRIPT; if (!pIADT->decode(pArithDecoder, &STRIPT)) @@ -335,7 +333,7 @@ CJBig2_Image* CJBig2_TRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder, if ((int)(WOI + RDWI) < 0 || (int)(HOI + RDHI) < 0) return nullptr; - std::unique_ptr pGRRD(new CJBig2_GRRDProc()); + auto pGRRD = pdfium::MakeUnique(); pGRRD->GRW = WOI + RDWI; pGRRD->GRH = HOI + RDHI; pGRRD->GRTEMPLATE = SBRTEMPLATE; diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp index 19e5696c86..9f699e4da7 100644 --- a/core/fxcrt/fx_basic_util.cpp +++ b/core/fxcrt/fx_basic_util.cpp @@ -4,14 +4,15 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "core/fxcrt/fx_basic.h" -#include "core/fxcrt/fx_ext.h" - #include #include #include #include +#include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_ext.h" +#include "third_party/base/ptr_util.h" + bool FX_atonum(const CFX_ByteStringC& strc, void* pData) { if (strc.Find('.') != -1) { float* pFloat = static_cast(pData); @@ -142,7 +143,7 @@ void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { FX_FileHandle* FX_OpenFolder(const char* path) { #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ - std::unique_ptr pData(new CFindFileDataA); + auto pData = pdfium::MakeUnique(); pData->m_Handle = FindFirstFileExA((CFX_ByteString(path) + "/*.*").c_str(), FindExInfoStandard, &pData->m_FindData, FindExSearchNameMatch, nullptr, 0); diff --git a/core/fxge/android/fx_android_imp.cpp b/core/fxge/android/fx_android_imp.cpp index b8e7c5b218..e4fdd1e131 100644 --- a/core/fxge/android/fx_android_imp.cpp +++ b/core/fxge/android/fx_android_imp.cpp @@ -11,6 +11,7 @@ #include "core/fxge/android/cfpf_skiadevicemodule.h" #include "core/fxge/android/cfx_androidfontinfo.h" +#include "third_party/base/ptr_util.h" void CFX_GEModule::InitPlatform() { CFPF_SkiaDeviceModule* pDeviceModule = CFPF_GetSkiaDeviceModule(); @@ -19,7 +20,7 @@ void CFX_GEModule::InitPlatform() { CFPF_SkiaFontMgr* pFontMgr = pDeviceModule->GetFontMgr(); if (pFontMgr) { - std::unique_ptr pFontInfo(new CFX_AndroidFontInfo); + auto pFontInfo = pdfium::MakeUnique(); pFontInfo->Init(pFontMgr); m_pFontMgr->SetSystemFontInfo(std::move(pFontInfo)); } diff --git a/core/fxge/ge/cfx_fontcache.cpp b/core/fxge/ge/cfx_fontcache.cpp index 58cee06d42..1599c30b93 100644 --- a/core/fxge/ge/cfx_fontcache.cpp +++ b/core/fxge/ge/cfx_fontcache.cpp @@ -12,6 +12,7 @@ #include "core/fxge/cfx_facecache.h" #include "core/fxge/fx_font.h" #include "core/fxge/fx_freetype.h" +#include "third_party/base/ptr_util.h" CFX_FontCache::CountedFaceCache::CountedFaceCache() {} @@ -35,7 +36,7 @@ CFX_FaceCache* CFX_FontCache::GetCachedFace(const CFX_Font* pFont) { return counted_face_cache->m_Obj.get(); } - std::unique_ptr counted_face_cache(new CountedFaceCache); + auto counted_face_cache = pdfium::MakeUnique(); counted_face_cache->m_nCount = 2; CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); counted_face_cache->m_Obj.reset(face_cache); -- cgit v1.2.3