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

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

Issue 2355083002: Make CPDF_Array not do indirect object creation. (Closed)
Patch Set: Missed two references Created 4 years, 3 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_array.h" 7 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
8 8
9 #include <set> 9 #include <set>
10 10
11 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h" 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_name.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_number.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_reference.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_string.h"
16 #include "third_party/base/logging.h"
16 #include "third_party/base/stl_util.h" 17 #include "third_party/base/stl_util.h"
17 18
18 CPDF_Array::CPDF_Array() {} 19 CPDF_Array::CPDF_Array() {}
19 20
20 CPDF_Array::~CPDF_Array() { 21 CPDF_Array::~CPDF_Array() {
21 // Mark the object as deleted so that it will not be deleted again 22 // Mark the object as deleted so that it will not be deleted again
22 // in case of cyclic references. 23 // in case of cyclic references.
23 m_ObjNum = kInvalidObjNum; 24 m_ObjNum = kInvalidObjNum;
24 for (auto& it : m_Objects) { 25 for (auto& it : m_Objects) {
25 if (it) 26 if (it)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 if (nCount <= 0 || nCount > m_Objects.size() - i) 139 if (nCount <= 0 || nCount > m_Objects.size() - i)
139 return; 140 return;
140 141
141 for (size_t j = 0; j < nCount; ++j) { 142 for (size_t j = 0; j < nCount; ++j) {
142 if (CPDF_Object* p = m_Objects[i + j]) 143 if (CPDF_Object* p = m_Objects[i + j])
143 p->Release(); 144 p->Release();
144 } 145 }
145 m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount); 146 m_Objects.erase(m_Objects.begin() + i, m_Objects.begin() + i + nCount);
146 } 147 }
147 148
148 void CPDF_Array::SetAt(size_t i, 149 void CPDF_Array::SetAt(size_t i, CPDF_Object* pObj) {
149 CPDF_Object* pObj,
150 CPDF_IndirectObjectHolder* pObjs) {
151 ASSERT(IsArray()); 150 ASSERT(IsArray());
151 CHECK(!pObj || pObj->GetObjNum() == 0);
152 if (i >= m_Objects.size()) { 152 if (i >= m_Objects.size()) {
153 ASSERT(false); 153 ASSERT(false);
154 return; 154 return;
155 } 155 }
156 if (CPDF_Object* pOld = m_Objects[i]) 156 if (CPDF_Object* pOld = m_Objects[i])
157 pOld->Release(); 157 pOld->Release();
158 if (pObj->GetObjNum()) { 158
159 ASSERT(pObjs);
160 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
161 }
162 m_Objects[i] = pObj; 159 m_Objects[i] = pObj;
163 } 160 }
164 161
165 void CPDF_Array::InsertAt(size_t index, 162 void CPDF_Array::InsertAt(size_t index, CPDF_Object* pObj) {
166 CPDF_Object* pObj, 163 ASSERT(IsArray());
167 CPDF_IndirectObjectHolder* pObjs) { 164 CHECK(!pObj || pObj->GetObjNum() == 0);
168 if (pObj->GetObjNum()) {
169 ASSERT(pObjs);
170 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
171 }
172 if (index >= m_Objects.size()) { 165 if (index >= m_Objects.size()) {
173 // Allocate space first. 166 // Allocate space first.
174 m_Objects.resize(index + 1, nullptr); 167 m_Objects.resize(index + 1, nullptr);
175 m_Objects[index] = pObj; 168 m_Objects[index] = pObj;
176 } else { 169 } else {
177 // Directly insert. 170 // Directly insert.
178 m_Objects.insert(m_Objects.begin() + index, pObj); 171 m_Objects.insert(m_Objects.begin() + index, pObj);
179 } 172 }
180 } 173 }
181 174
182 void CPDF_Array::Add(CPDF_Object* pObj, CPDF_IndirectObjectHolder* pObjs) { 175 void CPDF_Array::Add(CPDF_Object* pObj) {
183 if (pObj->GetObjNum()) { 176 ASSERT(IsArray());
184 ASSERT(pObjs); 177 CHECK(!pObj || pObj->GetObjNum() == 0);
185 pObj = new CPDF_Reference(pObjs, pObj->GetObjNum());
186 }
187 m_Objects.push_back(pObj); 178 m_Objects.push_back(pObj);
188 } 179 }
189 180
190 void CPDF_Array::AddName(const CFX_ByteString& str) { 181 void CPDF_Array::AddName(const CFX_ByteString& str) {
191 ASSERT(IsArray());
192 Add(new CPDF_Name(str)); 182 Add(new CPDF_Name(str));
193 } 183 }
194 184
195 void CPDF_Array::AddString(const CFX_ByteString& str) { 185 void CPDF_Array::AddString(const CFX_ByteString& str) {
196 ASSERT(IsArray());
197 Add(new CPDF_String(str, FALSE)); 186 Add(new CPDF_String(str, FALSE));
198 } 187 }
199 188
200 void CPDF_Array::AddInteger(int i) { 189 void CPDF_Array::AddInteger(int i) {
201 ASSERT(IsArray());
202 Add(new CPDF_Number(i)); 190 Add(new CPDF_Number(i));
203 } 191 }
204 192
205 void CPDF_Array::AddNumber(FX_FLOAT f) { 193 void CPDF_Array::AddNumber(FX_FLOAT f) {
206 ASSERT(IsArray()); 194 Add(new CPDF_Number(f));
207 CPDF_Number* pNumber = new CPDF_Number(f);
208 Add(pNumber);
209 } 195 }
210 196
211 void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc, 197 void CPDF_Array::AddReference(CPDF_IndirectObjectHolder* pDoc,
212 uint32_t objnum) { 198 uint32_t objnum) {
213 ASSERT(IsArray());
214 Add(new CPDF_Reference(pDoc, objnum)); 199 Add(new CPDF_Reference(pDoc, objnum));
215 } 200 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_edit/fpdf_edit_create.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_array_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698