| OLD | NEW |
| 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 _ClearIndex(m_IndexDepth, m_IndexSize, (void**)m_pIndex); | 182 _ClearIndex(m_IndexDepth, m_IndexSize, (void**)m_pIndex); |
| 183 m_pIndex = NULL; | 183 m_pIndex = NULL; |
| 184 m_IndexDepth = 0; | 184 m_IndexDepth = 0; |
| 185 m_DataSize = 0; | 185 m_DataSize = 0; |
| 186 } | 186 } |
| 187 void* CFX_BaseSegmentedArray::Add() | 187 void* CFX_BaseSegmentedArray::Add() |
| 188 { | 188 { |
| 189 if (m_DataSize % m_SegmentSize) { | 189 if (m_DataSize % m_SegmentSize) { |
| 190 return GetAt(m_DataSize ++); | 190 return GetAt(m_DataSize ++); |
| 191 } | 191 } |
| 192 void* pSegment = FX_Alloc(FX_BYTE, m_UnitSize * m_SegmentSize); | 192 void* pSegment = FX_Alloc2D(FX_BYTE, m_UnitSize, m_SegmentSize); |
| 193 if (!pSegment) { | |
| 194 return NULL; | |
| 195 } | |
| 196 if (m_pIndex == NULL) { | 193 if (m_pIndex == NULL) { |
| 197 m_pIndex = pSegment; | 194 m_pIndex = pSegment; |
| 198 m_DataSize ++; | 195 m_DataSize ++; |
| 199 return pSegment; | 196 return pSegment; |
| 200 } | 197 } |
| 201 if (m_IndexDepth == 0) { | 198 if (m_IndexDepth == 0) { |
| 202 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); | 199 void** pIndex = (void**)FX_Alloc(void*, m_IndexSize); |
| 203 if (pIndex == NULL) { | 200 if (pIndex == NULL) { |
| 204 FX_Free(pSegment); | 201 FX_Free(pSegment); |
| 205 return NULL; | 202 return NULL; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 FX_Free(pIndex[i % m_IndexSize]); | 345 FX_Free(pIndex[i % m_IndexSize]); |
| 349 pIndex[i % m_IndexSize] = NULL; | 346 pIndex[i % m_IndexSize] = NULL; |
| 350 } | 347 } |
| 351 } else { | 348 } else { |
| 352 FX_Free(m_pIndex); | 349 FX_Free(m_pIndex); |
| 353 m_pIndex = NULL; | 350 m_pIndex = NULL; |
| 354 } | 351 } |
| 355 } | 352 } |
| 356 m_DataSize -= count; | 353 m_DataSize -= count; |
| 357 } | 354 } |
| OLD | NEW |