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

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

Issue 2640143003: Update safe numerics package to get bitwise ops (Closed)
Patch Set: 0 is a perfectly fine value of zero 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
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 = FX_Alloc(uint8_t, totalSize.ValueOrDie<size_t>());
jschuh 2017/01/23 17:05:19 Weird. I'm not sure how this compiles without doin
Tom Sepez 2017/01/23 18:19:14 Ok, I'll switch to the functional form just in cas
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>());
jschuh 2017/01/23 17:05:19 Same question for this and the other uses below.
Tom Sepez 2017/01/23 18:19:14 Done.
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698