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

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

Issue 2640143003: Update safe numerics package to get bitwise ops (Closed)
Patch Set: Address reviewer comments Created 3 years, 11 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/fxcrt/cfx_string_data_template.h ('k') | core/fxcrt/fx_basic_util.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 "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
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
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 }
OLDNEW
« no previous file with comments | « core/fxcrt/cfx_string_data_template.h ('k') | core/fxcrt/fx_basic_util.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698