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

Side by Side Diff: core/src/fxcrt/fx_basic_array.cpp

Issue 1143663008: Merge to XFA: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Rebased. Created 5 years, 7 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
« no previous file with comments | « core/src/fxcrt/extension.h ('k') | core/src/fxcrt/fx_basic_bstring.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 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 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 "../../include/fxcrt/fx_basic.h" 7 #include "../../include/fxcrt/fx_basic.h"
8 #include "../../../third_party/base/numerics/safe_math.h" 8 #include "../../../third_party/base/numerics/safe_math.h"
9 9
10 CFX_BasicArray::CFX_BasicArray(int unit_size) 10 CFX_BasicArray::CFX_BasicArray(int unit_size)
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 if (m_pData == NULL) { 34 if (m_pData == NULL) {
35 pdfium::base::CheckedNumeric<int> totalSize = nNewSize; 35 pdfium::base::CheckedNumeric<int> totalSize = nNewSize;
36 totalSize *= m_nUnitSize; 36 totalSize *= m_nUnitSize;
37 if (!totalSize.IsValid()) { 37 if (!totalSize.IsValid()) {
38 m_nSize = m_nMaxSize = 0; 38 m_nSize = m_nMaxSize = 0;
39 return FALSE; 39 return FALSE;
40 } 40 }
41 m_pData = FX_Alloc(FX_BYTE, totalSize.ValueOrDie()); 41 m_pData = FX_Alloc(FX_BYTE, totalSize.ValueOrDie());
42 if (!m_pData) {
43 m_nSize = m_nMaxSize = 0;
44 return FALSE;
45 }
46 m_nSize = m_nMaxSize = nNewSize; 42 m_nSize = m_nMaxSize = nNewSize;
47 } else if (nNewSize <= m_nMaxSize) { 43 } else if (nNewSize <= m_nMaxSize) {
48 if (nNewSize > m_nSize) { 44 if (nNewSize > m_nSize) {
49 FXSYS_memset32(m_pData + m_nSize * m_nUnitSize, 0, (nNewSize - m_nSi ze) * m_nUnitSize); 45 FXSYS_memset32(m_pData + m_nSize * m_nUnitSize, 0, (nNewSize - m_nSi ze) * m_nUnitSize);
50 } 46 }
51 m_nSize = nNewSize; 47 m_nSize = nNewSize;
52 } else { 48 } else {
53 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; 49 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize;
54 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; 50 pdfium::base::CheckedNumeric<int> totalSize = nNewMax;
55 totalSize *= m_nUnitSize; 51 totalSize *= m_nUnitSize;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return GetAt(m_DataSize ++); 186 return GetAt(m_DataSize ++);
191 } 187 }
192 void* pSegment = FX_Alloc2D(FX_BYTE, m_UnitSize, m_SegmentSize); 188 void* pSegment = FX_Alloc2D(FX_BYTE, m_UnitSize, m_SegmentSize);
193 if (m_pIndex == NULL) { 189 if (m_pIndex == NULL) {
194 m_pIndex = pSegment; 190 m_pIndex = pSegment;
195 m_DataSize ++; 191 m_DataSize ++;
196 return pSegment; 192 return pSegment;
197 } 193 }
198 if (m_IndexDepth == 0) { 194 if (m_IndexDepth == 0) {
199 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); 195 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
200 if (pIndex == NULL) {
201 FX_Free(pSegment);
202 return NULL;
203 }
204 pIndex[0] = m_pIndex; 196 pIndex[0] = m_pIndex;
205 pIndex[1] = pSegment; 197 pIndex[1] = pSegment;
206 m_pIndex = pIndex; 198 m_pIndex = pIndex;
207 m_DataSize ++; 199 m_DataSize ++;
208 m_IndexDepth ++; 200 m_IndexDepth ++;
209 return pSegment; 201 return pSegment;
210 } 202 }
211 int seg_index = m_DataSize / m_SegmentSize; 203 int seg_index = m_DataSize / m_SegmentSize;
212 if (seg_index % m_IndexSize) { 204 if (seg_index % m_IndexSize) {
213 void** pIndex = GetIndex(seg_index); 205 void** pIndex = GetIndex(seg_index);
214 pIndex[seg_index % m_IndexSize] = pSegment; 206 pIndex[seg_index % m_IndexSize] = pSegment;
215 m_DataSize ++; 207 m_DataSize ++;
216 return pSegment; 208 return pSegment;
217 } 209 }
218 int tree_size = 1; 210 int tree_size = 1;
219 int i; 211 int i;
220 for (i = 0; i < m_IndexDepth; i ++) { 212 for (i = 0; i < m_IndexDepth; i ++) {
221 tree_size *= m_IndexSize; 213 tree_size *= m_IndexSize;
222 } 214 }
223 if (m_DataSize == tree_size * m_SegmentSize) { 215 if (m_DataSize == tree_size * m_SegmentSize) {
224 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); 216 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
225 if (pIndex == NULL) {
226 FX_Free(pSegment);
227 return NULL;
228 }
229 pIndex[0] = m_pIndex; 217 pIndex[0] = m_pIndex;
230 m_pIndex = pIndex; 218 m_pIndex = pIndex;
231 m_IndexDepth ++; 219 m_IndexDepth ++;
232 } else { 220 } else {
233 tree_size /= m_IndexSize; 221 tree_size /= m_IndexSize;
234 } 222 }
235 void** pSpot = (void**)m_pIndex; 223 void** pSpot = (void**)m_pIndex;
236 for (i = 1; i < m_IndexDepth; i ++) { 224 for (i = 1; i < m_IndexDepth; i ++) {
237 if (pSpot[seg_index / tree_size] == NULL) { 225 if (pSpot[seg_index / tree_size] == NULL) {
238 pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize); 226 pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize);
239 if (pSpot[seg_index / tree_size] == NULL) {
240 break;
241 }
242 } 227 }
243 pSpot = (void**)pSpot[seg_index / tree_size]; 228 pSpot = (void**)pSpot[seg_index / tree_size];
244 seg_index = seg_index % tree_size; 229 seg_index = seg_index % tree_size;
245 tree_size /= m_IndexSize; 230 tree_size /= m_IndexSize;
246 } 231 }
247 if (i < m_IndexDepth) { 232 if (i < m_IndexDepth) {
248 FX_Free(pSegment); 233 FX_Free(pSegment);
249 RemoveAll(); 234 RemoveAll();
250 return NULL; 235 return NULL;
251 } 236 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 FX_Free(pIndex[i % m_IndexSize]); 330 FX_Free(pIndex[i % m_IndexSize]);
346 pIndex[i % m_IndexSize] = NULL; 331 pIndex[i % m_IndexSize] = NULL;
347 } 332 }
348 } else { 333 } else {
349 FX_Free(m_pIndex); 334 FX_Free(m_pIndex);
350 m_pIndex = NULL; 335 m_pIndex = NULL;
351 } 336 }
352 } 337 }
353 m_DataSize -= count; 338 m_DataSize -= count;
354 } 339 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/extension.h ('k') | core/src/fxcrt/fx_basic_bstring.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698