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

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

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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 }
42 m_nSize = m_nMaxSize = nNewSize; 46 m_nSize = m_nMaxSize = nNewSize;
43 } else if (nNewSize <= m_nMaxSize) { 47 } else if (nNewSize <= m_nMaxSize) {
44 if (nNewSize > m_nSize) { 48 if (nNewSize > m_nSize) {
45 FXSYS_memset32(m_pData + m_nSize * m_nUnitSize, 0, (nNewSize - m_nSi ze) * m_nUnitSize); 49 FXSYS_memset32(m_pData + m_nSize * m_nUnitSize, 0, (nNewSize - m_nSi ze) * m_nUnitSize);
46 } 50 }
47 m_nSize = nNewSize; 51 m_nSize = nNewSize;
48 } else { 52 } else {
49 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; 53 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize;
50 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; 54 pdfium::base::CheckedNumeric<int> totalSize = nNewMax;
51 totalSize *= m_nUnitSize; 55 totalSize *= m_nUnitSize;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return GetAt(m_DataSize ++); 190 return GetAt(m_DataSize ++);
187 } 191 }
188 void* pSegment = FX_Alloc2D(FX_BYTE, m_UnitSize, m_SegmentSize); 192 void* pSegment = FX_Alloc2D(FX_BYTE, m_UnitSize, m_SegmentSize);
189 if (m_pIndex == NULL) { 193 if (m_pIndex == NULL) {
190 m_pIndex = pSegment; 194 m_pIndex = pSegment;
191 m_DataSize ++; 195 m_DataSize ++;
192 return pSegment; 196 return pSegment;
193 } 197 }
194 if (m_IndexDepth == 0) { 198 if (m_IndexDepth == 0) {
195 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); 199 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
200 if (pIndex == NULL) {
201 FX_Free(pSegment);
202 return NULL;
203 }
196 pIndex[0] = m_pIndex; 204 pIndex[0] = m_pIndex;
197 pIndex[1] = pSegment; 205 pIndex[1] = pSegment;
198 m_pIndex = pIndex; 206 m_pIndex = pIndex;
199 m_DataSize ++; 207 m_DataSize ++;
200 m_IndexDepth ++; 208 m_IndexDepth ++;
201 return pSegment; 209 return pSegment;
202 } 210 }
203 int seg_index = m_DataSize / m_SegmentSize; 211 int seg_index = m_DataSize / m_SegmentSize;
204 if (seg_index % m_IndexSize) { 212 if (seg_index % m_IndexSize) {
205 void** pIndex = GetIndex(seg_index); 213 void** pIndex = GetIndex(seg_index);
206 pIndex[seg_index % m_IndexSize] = pSegment; 214 pIndex[seg_index % m_IndexSize] = pSegment;
207 m_DataSize ++; 215 m_DataSize ++;
208 return pSegment; 216 return pSegment;
209 } 217 }
210 int tree_size = 1; 218 int tree_size = 1;
211 int i; 219 int i;
212 for (i = 0; i < m_IndexDepth; i ++) { 220 for (i = 0; i < m_IndexDepth; i ++) {
213 tree_size *= m_IndexSize; 221 tree_size *= m_IndexSize;
214 } 222 }
215 if (m_DataSize == tree_size * m_SegmentSize) { 223 if (m_DataSize == tree_size * m_SegmentSize) {
216 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); 224 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize);
225 if (pIndex == NULL) {
226 FX_Free(pSegment);
227 return NULL;
228 }
217 pIndex[0] = m_pIndex; 229 pIndex[0] = m_pIndex;
218 m_pIndex = pIndex; 230 m_pIndex = pIndex;
219 m_IndexDepth ++; 231 m_IndexDepth ++;
220 } else { 232 } else {
221 tree_size /= m_IndexSize; 233 tree_size /= m_IndexSize;
222 } 234 }
223 void** pSpot = (void**)m_pIndex; 235 void** pSpot = (void**)m_pIndex;
224 for (i = 1; i < m_IndexDepth; i ++) { 236 for (i = 1; i < m_IndexDepth; i ++) {
225 if (pSpot[seg_index / tree_size] == NULL) { 237 if (pSpot[seg_index / tree_size] == NULL) {
226 pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize); 238 pSpot[seg_index / tree_size] = (void*)FX_Alloc(void*, m_IndexSize);
239 if (pSpot[seg_index / tree_size] == NULL) {
240 break;
241 }
227 } 242 }
228 pSpot = (void**)pSpot[seg_index / tree_size]; 243 pSpot = (void**)pSpot[seg_index / tree_size];
229 seg_index = seg_index % tree_size; 244 seg_index = seg_index % tree_size;
230 tree_size /= m_IndexSize; 245 tree_size /= m_IndexSize;
231 } 246 }
232 if (i < m_IndexDepth) { 247 if (i < m_IndexDepth) {
233 FX_Free(pSegment); 248 FX_Free(pSegment);
234 RemoveAll(); 249 RemoveAll();
235 return NULL; 250 return NULL;
236 } 251 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 FX_Free(pIndex[i % m_IndexSize]); 345 FX_Free(pIndex[i % m_IndexSize]);
331 pIndex[i % m_IndexSize] = NULL; 346 pIndex[i % m_IndexSize] = NULL;
332 } 347 }
333 } else { 348 } else {
334 FX_Free(m_pIndex); 349 FX_Free(m_pIndex);
335 m_pIndex = NULL; 350 m_pIndex = NULL;
336 } 351 }
337 } 352 }
338 m_DataSize -= count; 353 m_DataSize -= count;
339 } 354 }
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