| OLD | NEW |
| 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_indirect_object_holder.h" | 7 #include "core/fpdfapi/parser/cpdf_indirect_object_holder.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/parser/cpdf_object.h" | 9 #include "core/fpdfapi/parser/cpdf_object.h" |
| 10 #include "core/fpdfapi/parser/cpdf_parser.h" | 10 #include "core/fpdfapi/parser/cpdf_parser.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 m_LastObjNum = std::max(m_LastObjNum, objnum); | 36 m_LastObjNum = std::max(m_LastObjNum, objnum); |
| 37 m_IndirectObjs[objnum] = std::move(pNewObj); | 37 m_IndirectObjs[objnum] = std::move(pNewObj); |
| 38 return m_IndirectObjs[objnum].get(); | 38 return m_IndirectObjs[objnum].get(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 std::unique_ptr<CPDF_Object> CPDF_IndirectObjectHolder::ParseIndirectObject( | 41 std::unique_ptr<CPDF_Object> CPDF_IndirectObjectHolder::ParseIndirectObject( |
| 42 uint32_t objnum) { | 42 uint32_t objnum) { |
| 43 return nullptr; | 43 return nullptr; |
| 44 } | 44 } |
| 45 | 45 |
| 46 uint32_t CPDF_IndirectObjectHolder::AddIndirectObject(CPDF_Object* pObj) { | 46 CPDF_Object* CPDF_IndirectObjectHolder::AddIndirectObject( |
| 47 std::unique_ptr<CPDF_Object> pObj) { |
| 47 CHECK(!pObj->m_ObjNum); | 48 CHECK(!pObj->m_ObjNum); |
| 48 m_LastObjNum++; | 49 CPDF_Object* pUnowned = pObj.get(); |
| 50 pObj->m_ObjNum = ++m_LastObjNum; |
| 49 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. | 51 m_IndirectObjs[m_LastObjNum].release(); // TODO(tsepez): stop this leak. |
| 50 m_IndirectObjs[m_LastObjNum].reset(pObj); | 52 m_IndirectObjs[m_LastObjNum] = std::move(pObj); |
| 51 pObj->m_ObjNum = m_LastObjNum; | 53 return pUnowned; |
| 52 return m_LastObjNum; | |
| 53 } | 54 } |
| 54 | 55 |
| 55 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( | 56 bool CPDF_IndirectObjectHolder::ReplaceIndirectObjectIfHigherGeneration( |
| 56 uint32_t objnum, | 57 uint32_t objnum, |
| 57 std::unique_ptr<CPDF_Object> pObj) { | 58 std::unique_ptr<CPDF_Object> pObj) { |
| 58 ASSERT(objnum); | 59 ASSERT(objnum); |
| 59 if (!pObj) | 60 if (!pObj) |
| 60 return false; | 61 return false; |
| 61 | 62 |
| 62 CPDF_Object* pOldObj = GetIndirectObject(objnum); | 63 CPDF_Object* pOldObj = GetIndirectObject(objnum); |
| 63 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) | 64 if (pOldObj && pObj->GetGenNum() <= pOldObj->GetGenNum()) |
| 64 return false; | 65 return false; |
| 65 | 66 |
| 66 pObj->m_ObjNum = objnum; | 67 pObj->m_ObjNum = objnum; |
| 67 m_IndirectObjs[objnum] = std::move(pObj); | 68 m_IndirectObjs[objnum] = std::move(pObj); |
| 68 m_LastObjNum = std::max(m_LastObjNum, objnum); | 69 m_LastObjNum = std::max(m_LastObjNum, objnum); |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { | 73 void CPDF_IndirectObjectHolder::DeleteIndirectObject(uint32_t objnum) { |
| 73 CPDF_Object* pObj = GetIndirectObject(objnum); | 74 CPDF_Object* pObj = GetIndirectObject(objnum); |
| 74 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) | 75 if (!pObj || pObj->GetObjNum() == CPDF_Object::kInvalidObjNum) |
| 75 return; | 76 return; |
| 76 | 77 |
| 77 m_IndirectObjs.erase(objnum); | 78 m_IndirectObjs.erase(objnum); |
| 78 } | 79 } |
| OLD | NEW |