Chromium Code Reviews| 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 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 7 #ifndef CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 8 #define CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <cstdlib> | |
| 11 #include <memory> | 12 #include <memory> |
| 12 | 13 |
| 13 #include "core/fxcrt/include/fx_memory.h" | 14 #include "core/fxcrt/include/fx_memory.h" |
| 14 #include "core/fxcrt/include/fx_stream.h" | 15 #include "core/fxcrt/include/fx_stream.h" |
| 15 #include "core/fxcrt/include/fx_string.h" | 16 #include "core/fxcrt/include/fx_string.h" |
| 16 #include "core/fxcrt/include/fx_system.h" | 17 #include "core/fxcrt/include/fx_system.h" |
| 17 | 18 |
| 18 class CFX_BinaryBuf { | 19 class CFX_BinaryBuf { |
| 19 public: | 20 public: |
| 20 CFX_BinaryBuf(); | 21 CFX_BinaryBuf(); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 int GetSize() const { return m_nSize; } | 271 int GetSize() const { return m_nSize; } |
| 271 | 272 |
| 272 int GetUpperBound() const { return m_nSize - 1; } | 273 int GetUpperBound() const { return m_nSize - 1; } |
| 273 | 274 |
| 274 FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } | 275 FX_BOOL SetSize(int nNewSize) { return CFX_BasicArray::SetSize(nNewSize); } |
| 275 | 276 |
| 276 void RemoveAll() { SetSize(0); } | 277 void RemoveAll() { SetSize(0); } |
| 277 | 278 |
| 278 const TYPE GetAt(int nIndex) const { | 279 const TYPE GetAt(int nIndex) const { |
| 279 if (nIndex < 0 || nIndex >= m_nSize) { | 280 if (nIndex < 0 || nIndex >= m_nSize) { |
| 280 return (const TYPE&)(*(volatile const TYPE*)NULL); | 281 abort(); |
| 281 } | 282 } |
| 282 return ((const TYPE*)m_pData)[nIndex]; | 283 return ((const TYPE*)m_pData)[nIndex]; |
| 283 } | 284 } |
| 284 | 285 |
| 285 FX_BOOL SetAt(int nIndex, TYPE newElement) { | 286 FX_BOOL SetAt(int nIndex, TYPE newElement) { |
| 286 if (nIndex < 0 || nIndex >= m_nSize) { | 287 if (nIndex < 0 || nIndex >= m_nSize) { |
| 287 return FALSE; | 288 return FALSE; |
| 288 } | 289 } |
| 289 ((TYPE*)m_pData)[nIndex] = newElement; | 290 ((TYPE*)m_pData)[nIndex] = newElement; |
| 290 return TRUE; | 291 return TRUE; |
| 291 } | 292 } |
| 292 | 293 |
| 293 TYPE& ElementAt(int nIndex) { | 294 TYPE& ElementAt(int nIndex) { |
| 294 if (nIndex < 0 || nIndex >= m_nSize) { | 295 if (nIndex < 0 || nIndex >= m_nSize) { |
| 295 return *(TYPE*)NULL; | 296 abort(); |
|
dsinclair
2016/05/16 17:41:02
I don't think this is safe to do. We can't assume
hans
2016/05/16 17:48:26
Getting a reference bound to null as the return va
Tom Sepez
2016/05/16 17:49:18
But .. they wanted to crash here, so this should b
Nico
2016/05/16 17:49:34
References pointing to null have undefined behavio
| |
| 296 } | 297 } |
| 297 return ((TYPE*)m_pData)[nIndex]; | 298 return ((TYPE*)m_pData)[nIndex]; |
| 298 } | 299 } |
| 299 | 300 |
| 300 const TYPE* GetData() const { return (const TYPE*)m_pData; } | 301 const TYPE* GetData() const { return (const TYPE*)m_pData; } |
| 301 | 302 |
| 302 TYPE* GetData() { return (TYPE*)m_pData; } | 303 TYPE* GetData() { return (TYPE*)m_pData; } |
| 303 | 304 |
| 304 FX_BOOL SetAtGrow(int nIndex, TYPE newElement) { | 305 FX_BOOL SetAtGrow(int nIndex, TYPE newElement) { |
| 305 if (nIndex < 0) | 306 if (nIndex < 0) |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1062 FX_FLOAT c; | 1063 FX_FLOAT c; |
| 1063 FX_FLOAT d; | 1064 FX_FLOAT d; |
| 1064 FX_FLOAT e; | 1065 FX_FLOAT e; |
| 1065 FX_FLOAT f; | 1066 FX_FLOAT f; |
| 1066 FX_FLOAT g; | 1067 FX_FLOAT g; |
| 1067 FX_FLOAT h; | 1068 FX_FLOAT h; |
| 1068 FX_FLOAT i; | 1069 FX_FLOAT i; |
| 1069 }; | 1070 }; |
| 1070 | 1071 |
| 1071 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ | 1072 #endif // CORE_FXCRT_INCLUDE_FX_BASIC_H_ |
| OLD | NEW |