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 "core/fxcrt/fx_basic.h" | 7 #include "core/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 15 matching lines...) Expand all Loading... |
26 return 0 == nNewSize; | 26 return 0 == nNewSize; |
27 } | 27 } |
28 | 28 |
29 if (!m_pData) { | 29 if (!m_pData) { |
30 pdfium::base::CheckedNumeric<int> totalSize = nNewSize; | 30 pdfium::base::CheckedNumeric<int> totalSize = nNewSize; |
31 totalSize *= m_nUnitSize; | 31 totalSize *= m_nUnitSize; |
32 if (!totalSize.IsValid()) { | 32 if (!totalSize.IsValid()) { |
33 m_nSize = m_nMaxSize = 0; | 33 m_nSize = m_nMaxSize = 0; |
34 return false; | 34 return false; |
35 } | 35 } |
36 m_pData = FX_Alloc(uint8_t, totalSize.ValueOrDie()); | 36 m_pData = FX_Alloc(uint8_t, totalSize.ValueOrDie<size_t>()); |
37 m_nSize = m_nMaxSize = nNewSize; | 37 m_nSize = m_nMaxSize = nNewSize; |
38 } else if (nNewSize <= m_nMaxSize) { | 38 } else if (nNewSize <= m_nMaxSize) { |
39 if (nNewSize > m_nSize) { | 39 if (nNewSize > m_nSize) { |
40 FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0, | 40 FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0, |
41 (nNewSize - m_nSize) * m_nUnitSize); | 41 (nNewSize - m_nSize) * m_nUnitSize); |
42 } | 42 } |
43 m_nSize = nNewSize; | 43 m_nSize = nNewSize; |
44 } else { | 44 } else { |
45 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; | 45 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; |
46 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; | 46 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; |
47 totalSize *= m_nUnitSize; | 47 totalSize *= m_nUnitSize; |
48 if (!totalSize.IsValid() || nNewMax < m_nSize) { | 48 if (!totalSize.IsValid() || nNewMax < m_nSize) { |
49 return false; | 49 return false; |
50 } | 50 } |
51 uint8_t* pNewData = FX_Realloc(uint8_t, m_pData, totalSize.ValueOrDie()); | 51 uint8_t* pNewData = |
| 52 FX_Realloc(uint8_t, m_pData, totalSize.ValueOrDie<size_t>()); |
52 if (!pNewData) { | 53 if (!pNewData) { |
53 return false; | 54 return false; |
54 } | 55 } |
55 FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, | 56 FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, |
56 (nNewMax - m_nSize) * m_nUnitSize); | 57 (nNewMax - m_nSize) * m_nUnitSize); |
57 m_pData = pNewData; | 58 m_pData = pNewData; |
58 m_nSize = nNewSize; | 59 m_nSize = nNewSize; |
59 m_nMaxSize = nNewMax; | 60 m_nMaxSize = nNewMax; |
60 } | 61 } |
61 return true; | 62 return true; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 FXSYS_memcpy(m_pData + nStartIndex * m_nUnitSize, pNewArray->m_pData, | 128 FXSYS_memcpy(m_pData + nStartIndex * m_nUnitSize, pNewArray->m_pData, |
128 pNewArray->m_nSize * m_nUnitSize); | 129 pNewArray->m_nSize * m_nUnitSize); |
129 return true; | 130 return true; |
130 } | 131 } |
131 const void* CFX_BasicArray::GetDataPtr(int index) const { | 132 const void* CFX_BasicArray::GetDataPtr(int index) const { |
132 if (index < 0 || index >= m_nSize || !m_pData) { | 133 if (index < 0 || index >= m_nSize || !m_pData) { |
133 return nullptr; | 134 return nullptr; |
134 } | 135 } |
135 return m_pData + index * m_nUnitSize; | 136 return m_pData + index * m_nUnitSize; |
136 } | 137 } |
OLD | NEW |