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

Side by Side Diff: core/fpdfapi/fpdf_parser/cpdf_indirect_object_holder.cpp

Issue 1841643002: Code change to avoid signed/unsigned mismatch warnings (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 8 months 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
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/fpdf_parser/include/cpdf_indirect_object_holder.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_indirect_object_holder.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h" 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_object.h"
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h"
11 11
12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser) 12 CPDF_IndirectObjectHolder::CPDF_IndirectObjectHolder(CPDF_Parser* pParser)
13 : m_pParser(pParser), m_LastObjNum(0) { 13 : m_pParser(pParser), m_LastObjNum(0) {
14 if (pParser) 14 if (pParser)
15 m_LastObjNum = m_pParser->GetLastObjNum(); 15 m_LastObjNum = m_pParser->GetLastObjNum();
16 } 16 }
17 17
18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() { 18 CPDF_IndirectObjectHolder::~CPDF_IndirectObjectHolder() {
19 for (const auto& pair : m_IndirectObjs) 19 for (const auto& pair : m_IndirectObjs)
20 pair.second->Destroy(); 20 pair.second->Destroy();
21 } 21 }
22 22
23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) { 23 CPDF_Object* CPDF_IndirectObjectHolder::GetIndirectObject(uint32_t objnum) {
24 if (objnum == 0) 24 if (objnum == 0)
25 return nullptr; 25 return nullptr;
26 26
27 auto it = m_IndirectObjs.find(objnum); 27 auto it = m_IndirectObjs.find(objnum);
28 if (it != m_IndirectObjs.end()) 28 if (it != m_IndirectObjs.end())
29 return it->second->GetObjNum() != -1 ? it->second : nullptr; 29 return it->second->GetObjNum() != CPDF_Object::kInvalidObjNum ? it->second
30 : nullptr;
30 31
31 if (!m_pParser) 32 if (!m_pParser)
32 return nullptr; 33 return nullptr;
33 34
34 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum); 35 CPDF_Object* pObj = m_pParser->ParseIndirectObject(this, objnum);
35 if (!pObj) 36 if (!pObj)
36 return nullptr; 37 return nullptr;
37 38
38 pObj->m_ObjNum = objnum; 39 pObj->m_ObjNum = objnum;
39 m_LastObjNum = std::max(m_LastObjNum, objnum); 40 m_LastObjNum = std::max(m_LastObjNum, objnum);
40 if (m_IndirectObjs[objnum]) 41 if (m_IndirectObjs[objnum])
41 m_IndirectObjs[objnum]->Destroy(); 42 m_IndirectObjs[objnum]->Destroy();
42 43
43 m_IndirectObjs[objnum] = pObj; 44 m_IndirectObjs[objnum] = pObj;
44 return pObj; 45 return pObj;
45 } 46 }
46 47
47 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { 48 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) {
48 if (pObj->m_ObjNum) 49 if (pObj->m_ObjNum)
49 return pObj->m_ObjNum; 50 return pObj->m_ObjNum;
50 51
51 m_LastObjNum++; 52 m_LastObjNum++;
52 m_IndirectObjs[m_LastObjNum] = pObj; 53 m_IndirectObjs[m_LastObjNum] = pObj;
53 pObj->m_ObjNum = m_LastObjNum; 54 pObj->m_ObjNum = m_LastObjNum;
54 return m_LastObjNum; 55 return m_LastObjNum;
55 } 56 }
56 57
57 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) { 58 void CPDF_IndirectObjectHolder::ReleaseIndirectObject(uint32_t objnum) {
58 auto it = m_IndirectObjs.find(objnum); 59 auto it = m_IndirectObjs.find(objnum);
59 if (it == m_IndirectObjs.end() || it->second->GetObjNum() == -1) 60 if (it == m_IndirectObjs.end() ||
61 it->second->GetObjNum() == CPDF_Object::kInvalidObjNum) {
60 return; 62 return;
63 }
61 it->second->Destroy(); 64 it->second->Destroy();
62 m_IndirectObjs.erase(it); 65 m_IndirectObjs.erase(it);
63 } 66 }
64 67
65 FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(uint32_t objnum, 68 FX_BOOL CPDF_IndirectObjectHolder::InsertIndirectObject(uint32_t objnum,
66 CPDF_Object* pObj) { 69 CPDF_Object* pObj) {
67 if (!objnum || !pObj) 70 if (!objnum || !pObj)
68 return FALSE; 71 return FALSE;
69 auto it = m_IndirectObjs.find(objnum); 72 auto it = m_IndirectObjs.find(objnum);
70 if (it != m_IndirectObjs.end()) { 73 if (it != m_IndirectObjs.end()) {
71 if (pObj->GetGenNum() <= it->second->GetGenNum()) { 74 if (pObj->GetGenNum() <= it->second->GetGenNum()) {
72 pObj->Destroy(); 75 pObj->Destroy();
73 return FALSE; 76 return FALSE;
74 } 77 }
75 it->second->Destroy(); 78 it->second->Destroy();
76 } 79 }
77 pObj->m_ObjNum = objnum; 80 pObj->m_ObjNum = objnum;
78 m_IndirectObjs[objnum] = pObj; 81 m_IndirectObjs[objnum] = pObj;
79 m_LastObjNum = std::max(m_LastObjNum, objnum); 82 m_LastObjNum = std::max(m_LastObjNum, objnum);
80 return TRUE; 83 return TRUE;
81 } 84 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp ('k') | core/fpdfapi/fpdf_parser/include/cpdf_array.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698