| 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 "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
| 8 #include "../../../third_party/numerics/safe_math.h" | 8 #include "../../../third_party/base/numerics/safe_math.h" |
| 9 | 9 |
| 10 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) | 10 static int _Buffer_itoa(char* buf, int i, FX_DWORD flags) |
| 11 { | 11 { |
| 12 if (i == 0) { | 12 if (i == 0) { |
| 13 buf[0] = '0'; | 13 buf[0] = '0'; |
| 14 return 1; | 14 return 1; |
| 15 } | 15 } |
| 16 char buf1[32]; | 16 char buf1[32]; |
| 17 int buf_pos = 31; | 17 int buf_pos = 31; |
| 18 FX_DWORD u = i; | 18 FX_DWORD u = i; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 45 char buf[32]; | 45 char buf[32]; |
| 46 return CFX_ByteStringC(buf, _Buffer_itoa(buf, i, flags)); | 46 return CFX_ByteStringC(buf, _Buffer_itoa(buf, i, flags)); |
| 47 } | 47 } |
| 48 static CFX_StringData* FX_AllocString(int nLen) | 48 static CFX_StringData* FX_AllocString(int nLen) |
| 49 { | 49 { |
| 50 // |nLen| is currently declared as in |int|. TODO(palmer): It should be | 50 // |nLen| is currently declared as in |int|. TODO(palmer): It should be |
| 51 // a |size_t|, or at least unsigned. | 51 // a |size_t|, or at least unsigned. |
| 52 if (nLen == 0 || nLen < 0) { | 52 if (nLen == 0 || nLen < 0) { |
| 53 return NULL; | 53 return NULL; |
| 54 } | 54 } |
| 55 base::CheckedNumeric<int> nSize = nLen; | 55 pdfium::base::CheckedNumeric<int> nSize = nLen; |
| 56 nSize += sizeof(long) * 3 + 1; | 56 nSize += sizeof(long) * 3 + 1; |
| 57 CFX_StringData* pData = (CFX_StringData*)FX_Alloc(FX_BYTE, nSize.ValueOrDie(
)); | 57 CFX_StringData* pData = (CFX_StringData*)FX_Alloc(FX_BYTE, nSize.ValueOrDie(
)); |
| 58 if (!pData) { | 58 if (!pData) { |
| 59 return NULL; | 59 return NULL; |
| 60 } | 60 } |
| 61 pData->m_nAllocLength = nLen; | 61 pData->m_nAllocLength = nLen; |
| 62 pData->m_nDataLength = nLen; | 62 pData->m_nDataLength = nLen; |
| 63 pData->m_nRefs = 1; | 63 pData->m_nRefs = 1; |
| 64 pData->m_String[nLen] = 0; | 64 pData->m_String[nLen] = 0; |
| 65 return pData; | 65 return pData; |
| (...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1169 FX_CHAR* pBuffer = (FX_CHAR*)(this + 1); | 1169 FX_CHAR* pBuffer = (FX_CHAR*)(this + 1); |
| 1170 FXSYS_memcpy32(pBuffer + m_Size, str.GetPtr(), len); | 1170 FXSYS_memcpy32(pBuffer + m_Size, str.GetPtr(), len); |
| 1171 m_Size += len; | 1171 m_Size += len; |
| 1172 } | 1172 } |
| 1173 void CFX_StringBufBase::Append(int i, FX_DWORD flags) | 1173 void CFX_StringBufBase::Append(int i, FX_DWORD flags) |
| 1174 { | 1174 { |
| 1175 char buf[32]; | 1175 char buf[32]; |
| 1176 int len = _Buffer_itoa(buf, i, flags); | 1176 int len = _Buffer_itoa(buf, i, flags); |
| 1177 Append(CFX_ByteStringC(buf, len)); | 1177 Append(CFX_ByteStringC(buf, len)); |
| 1178 } | 1178 } |
| OLD | NEW |