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

Side by Side Diff: core/fpdfapi/parser/cpdf_parser.cpp

Issue 2571913002: Avoid the ptr.reset(new XXX()) anti-pattern (Closed)
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_document_unittest.cpp ('k') | core/fpdfapi/parser/cpdf_stream.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/parser/cpdf_parser.h" 7 #include "core/fpdfapi/parser/cpdf_parser.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "core/fpdfapi/parser/cpdf_array.h" 13 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h" 14 #include "core/fpdfapi/parser/cpdf_crypto_handler.h"
15 #include "core/fpdfapi/parser/cpdf_dictionary.h" 15 #include "core/fpdfapi/parser/cpdf_dictionary.h"
16 #include "core/fpdfapi/parser/cpdf_document.h" 16 #include "core/fpdfapi/parser/cpdf_document.h"
17 #include "core/fpdfapi/parser/cpdf_linearized_header.h" 17 #include "core/fpdfapi/parser/cpdf_linearized_header.h"
18 #include "core/fpdfapi/parser/cpdf_number.h" 18 #include "core/fpdfapi/parser/cpdf_number.h"
19 #include "core/fpdfapi/parser/cpdf_reference.h" 19 #include "core/fpdfapi/parser/cpdf_reference.h"
20 #include "core/fpdfapi/parser/cpdf_security_handler.h" 20 #include "core/fpdfapi/parser/cpdf_security_handler.h"
21 #include "core/fpdfapi/parser/cpdf_stream.h" 21 #include "core/fpdfapi/parser/cpdf_stream.h"
22 #include "core/fpdfapi/parser/cpdf_stream_acc.h" 22 #include "core/fpdfapi/parser/cpdf_stream_acc.h"
23 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" 23 #include "core/fpdfapi/parser/cpdf_syntax_parser.h"
24 #include "core/fpdfapi/parser/fpdf_parser_utility.h" 24 #include "core/fpdfapi/parser/fpdf_parser_utility.h"
25 #include "core/fxcrt/fx_ext.h" 25 #include "core/fxcrt/fx_ext.h"
26 #include "core/fxcrt/fx_safe_types.h" 26 #include "core/fxcrt/fx_safe_types.h"
27 #include "third_party/base/ptr_util.h"
27 #include "third_party/base/stl_util.h" 28 #include "third_party/base/stl_util.h"
28 29
29 namespace { 30 namespace {
30 31
31 // A limit on the size of the xref table. Theoretical limits are higher, but 32 // A limit on the size of the xref table. Theoretical limits are higher, but
32 // this may be large enough in practice. 33 // this may be large enough in practice.
33 const int32_t kMaxXRefSize = 1048576; 34 const int32_t kMaxXRefSize = 1048576;
34 35
35 uint32_t GetVarInt(const uint8_t* p, int32_t n) { 36 uint32_t GetVarInt(const uint8_t* p, int32_t n) {
36 uint32_t result = 0; 37 uint32_t result = 0;
(...skipping 13 matching lines...) Expand all
50 } // namespace 51 } // namespace
51 52
52 CPDF_Parser::CPDF_Parser() 53 CPDF_Parser::CPDF_Parser()
53 : m_pDocument(nullptr), 54 : m_pDocument(nullptr),
54 m_bHasParsed(false), 55 m_bHasParsed(false),
55 m_bXRefStream(false), 56 m_bXRefStream(false),
56 m_bVersionUpdated(false), 57 m_bVersionUpdated(false),
57 m_FileVersion(0), 58 m_FileVersion(0),
58 m_pEncryptDict(nullptr), 59 m_pEncryptDict(nullptr),
59 m_dwXrefStartObjNum(0) { 60 m_dwXrefStartObjNum(0) {
60 m_pSyntax.reset(new CPDF_SyntaxParser); 61 m_pSyntax = pdfium::MakeUnique<CPDF_SyntaxParser>();
61 } 62 }
62 63
63 CPDF_Parser::~CPDF_Parser() { 64 CPDF_Parser::~CPDF_Parser() {
64 ReleaseEncryptHandler(); 65 ReleaseEncryptHandler();
65 SetEncryptDictionary(nullptr); 66 SetEncryptDictionary(nullptr);
66 } 67 }
67 68
68 uint32_t CPDF_Parser::GetLastObjNum() const { 69 uint32_t CPDF_Parser::GetLastObjNum() const {
69 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first; 70 return m_ObjectInfo.empty() ? 0 : m_ObjectInfo.rbegin()->first;
70 } 71 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (pEncryptObj) 236 if (pEncryptObj)
236 SetEncryptDictionary(pEncryptObj->GetDict()); 237 SetEncryptDictionary(pEncryptObj->GetDict());
237 } 238 }
238 } 239 }
239 240
240 if (m_pEncryptDict) { 241 if (m_pEncryptDict) {
241 CFX_ByteString filter = m_pEncryptDict->GetStringFor("Filter"); 242 CFX_ByteString filter = m_pEncryptDict->GetStringFor("Filter");
242 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler; 243 std::unique_ptr<CPDF_SecurityHandler> pSecurityHandler;
243 Error err = HANDLER_ERROR; 244 Error err = HANDLER_ERROR;
244 if (filter == "Standard") { 245 if (filter == "Standard") {
245 pSecurityHandler.reset(new CPDF_SecurityHandler); 246 pSecurityHandler = pdfium::MakeUnique<CPDF_SecurityHandler>();
246 err = PASSWORD_ERROR; 247 err = PASSWORD_ERROR;
247 } 248 }
248 if (!pSecurityHandler) 249 if (!pSecurityHandler)
249 return HANDLER_ERROR; 250 return HANDLER_ERROR;
250 251
251 if (!pSecurityHandler->OnInit(this, m_pEncryptDict)) 252 if (!pSecurityHandler->OnInit(this, m_pEncryptDict))
252 return err; 253 return err;
253 254
254 m_pSecurityHandler = std::move(pSecurityHandler); 255 m_pSecurityHandler = std::move(pSecurityHandler);
255 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler( 256 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler(
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) && 1570 if (!LoadLinearizedAllCrossRefV4(m_LastXRefOffset, m_dwXrefStartObjNum) &&
1570 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) { 1571 !LoadLinearizedAllCrossRefV5(m_LastXRefOffset)) {
1571 m_LastXRefOffset = 0; 1572 m_LastXRefOffset = 0;
1572 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1573 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1573 return FORMAT_ERROR; 1574 return FORMAT_ERROR;
1574 } 1575 }
1575 1576
1576 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum; 1577 m_pSyntax->m_MetadataObjnum = dwSaveMetadataObjnum;
1577 return SUCCESS; 1578 return SUCCESS;
1578 } 1579 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_document_unittest.cpp ('k') | core/fpdfapi/parser/cpdf_stream.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698