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 = |
| 37 FX_Alloc(uint8_t, pdfium::base::ValueOrDieForType<size_t>(totalSize)); |
37 m_nSize = m_nMaxSize = nNewSize; | 38 m_nSize = m_nMaxSize = nNewSize; |
38 } else if (nNewSize <= m_nMaxSize) { | 39 } else if (nNewSize <= m_nMaxSize) { |
39 if (nNewSize > m_nSize) { | 40 if (nNewSize > m_nSize) { |
40 FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0, | 41 FXSYS_memset(m_pData + m_nSize * m_nUnitSize, 0, |
41 (nNewSize - m_nSize) * m_nUnitSize); | 42 (nNewSize - m_nSize) * m_nUnitSize); |
42 } | 43 } |
43 m_nSize = nNewSize; | 44 m_nSize = nNewSize; |
44 } else { | 45 } else { |
45 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; | 46 int nNewMax = nNewSize < m_nMaxSize ? m_nMaxSize : nNewSize; |
46 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; | 47 pdfium::base::CheckedNumeric<int> totalSize = nNewMax; |
47 totalSize *= m_nUnitSize; | 48 totalSize *= m_nUnitSize; |
48 if (!totalSize.IsValid() || nNewMax < m_nSize) { | 49 if (!totalSize.IsValid() || nNewMax < m_nSize) { |
49 return false; | 50 return false; |
50 } | 51 } |
51 uint8_t* pNewData = FX_Realloc(uint8_t, m_pData, totalSize.ValueOrDie()); | 52 uint8_t* pNewData = FX_Realloc( |
| 53 uint8_t, m_pData, pdfium::base::ValueOrDieForType<size_t>(totalSize)); |
52 if (!pNewData) { | 54 if (!pNewData) { |
53 return false; | 55 return false; |
54 } | 56 } |
55 FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, | 57 FXSYS_memset(pNewData + m_nSize * m_nUnitSize, 0, |
56 (nNewMax - m_nSize) * m_nUnitSize); | 58 (nNewMax - m_nSize) * m_nUnitSize); |
57 m_pData = pNewData; | 59 m_pData = pNewData; |
58 m_nSize = nNewSize; | 60 m_nSize = nNewSize; |
59 m_nMaxSize = nNewMax; | 61 m_nMaxSize = nNewMax; |
60 } | 62 } |
61 return true; | 63 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, | 129 FXSYS_memcpy(m_pData + nStartIndex * m_nUnitSize, pNewArray->m_pData, |
128 pNewArray->m_nSize * m_nUnitSize); | 130 pNewArray->m_nSize * m_nUnitSize); |
129 return true; | 131 return true; |
130 } | 132 } |
131 const void* CFX_BasicArray::GetDataPtr(int index) const { | 133 const void* CFX_BasicArray::GetDataPtr(int index) const { |
132 if (index < 0 || index >= m_nSize || !m_pData) { | 134 if (index < 0 || index >= m_nSize || !m_pData) { |
133 return nullptr; | 135 return nullptr; |
134 } | 136 } |
135 return m_pData + index * m_nUnitSize; | 137 return m_pData + index * m_nUnitSize; |
136 } | 138 } |
OLD | NEW |