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 <stddef.h> // For offsetof(). | 7 #include <stddef.h> // For offsetof(). |
8 | 8 |
9 #include "../../include/fxcrt/fx_basic.h" | 9 #include "../../include/fxcrt/fx_basic.h" |
10 #include "../../../third_party/base/numerics/safe_math.h" | 10 #include "../../../third_party/base/numerics/safe_math.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 return; | 230 return; |
231 } | 231 } |
232 if (m_pData == NULL) { | 232 if (m_pData == NULL) { |
233 m_pData = StringData::Create(nSrcLen); | 233 m_pData = StringData::Create(nSrcLen); |
234 if (m_pData) { | 234 if (m_pData) { |
235 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_W
CHAR)); | 235 FXSYS_memcpy32(m_pData->m_String, lpszSrcData, nSrcLen * sizeof(FX_W
CHAR)); |
236 } | 236 } |
237 return; | 237 return; |
238 } | 238 } |
239 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA
llocLength) { | 239 if (m_pData->m_nRefs > 1 || m_pData->m_nDataLength + nSrcLen > m_pData->m_nA
llocLength) { |
240 StringData* pOldData = m_pData; | |
241 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa
ta); | 240 ConcatCopy(m_pData->m_nDataLength, m_pData->m_String, nSrcLen, lpszSrcDa
ta); |
242 pOldData->Release(); | |
243 } else { | 241 } else { |
244 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData,
nSrcLen * sizeof(FX_WCHAR)); | 242 FXSYS_memcpy32(m_pData->m_String + m_pData->m_nDataLength, lpszSrcData,
nSrcLen * sizeof(FX_WCHAR)); |
245 m_pData->m_nDataLength += nSrcLen; | 243 m_pData->m_nDataLength += nSrcLen; |
246 m_pData->m_String[m_pData->m_nDataLength] = 0; | 244 m_pData->m_String[m_pData->m_nDataLength] = 0; |
247 } | 245 } |
248 } | 246 } |
249 void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, | 247 void CFX_WideString::ConcatCopy(FX_STRSIZE nSrc1Len, FX_LPCWSTR lpszSrc1Data, |
250 FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data) | 248 FX_STRSIZE nSrc2Len, FX_LPCWSTR lpszSrc2Data) |
251 { | 249 { |
252 FX_STRSIZE nNewLen = nSrc1Len + nSrc2Len; | 250 FX_STRSIZE nNewLen = nSrc1Len + nSrc2Len; |
253 if (nNewLen == 0) { | 251 if (nNewLen <= 0) { |
254 return; | 252 return; |
255 } | 253 } |
| 254 // Don't release until done copying, might be one of the arguments. |
| 255 StringData* pOldData = m_pData; |
256 m_pData = StringData::Create(nNewLen); | 256 m_pData = StringData::Create(nNewLen); |
257 if (m_pData) { | 257 if (m_pData) { |
258 FXSYS_memcpy32(m_pData->m_String, lpszSrc1Data, nSrc1Len * sizeof(FX_WCH
AR)); | 258 wmemcpy(m_pData->m_String, lpszSrc1Data, nSrc1Len); |
259 FXSYS_memcpy32(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len * si
zeof(FX_WCHAR)); | 259 wmemcpy(m_pData->m_String + nSrc1Len, lpszSrc2Data, nSrc2Len); |
260 } | 260 } |
| 261 pOldData->Release(); |
261 } | 262 } |
262 void CFX_WideString::CopyBeforeWrite() | 263 void CFX_WideString::CopyBeforeWrite() |
263 { | 264 { |
264 if (m_pData == NULL || m_pData->m_nRefs <= 1) { | 265 if (m_pData == NULL || m_pData->m_nRefs <= 1) { |
265 return; | 266 return; |
266 } | 267 } |
267 StringData* pData = m_pData; | 268 StringData* pData = m_pData; |
268 m_pData->Release(); | 269 m_pData->Release(); |
269 FX_STRSIZE nDataLength = pData->m_nDataLength; | 270 FX_STRSIZE nDataLength = pData->m_nDataLength; |
270 m_pData = StringData::Create(nDataLength); | 271 m_pData = StringData::Create(nDataLength); |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1079 return (CFX_CharMap*)&g_DefaultJISMapper; | 1080 return (CFX_CharMap*)&g_DefaultJISMapper; |
1080 case 936: | 1081 case 936: |
1081 return (CFX_CharMap*)&g_DefaultGBKMapper; | 1082 return (CFX_CharMap*)&g_DefaultGBKMapper; |
1082 case 949: | 1083 case 949: |
1083 return (CFX_CharMap*)&g_DefaultUHCMapper; | 1084 return (CFX_CharMap*)&g_DefaultUHCMapper; |
1084 case 950: | 1085 case 950: |
1085 return (CFX_CharMap*)&g_DefaultBig5Mapper; | 1086 return (CFX_CharMap*)&g_DefaultBig5Mapper; |
1086 } | 1087 } |
1087 return NULL; | 1088 return NULL; |
1088 } | 1089 } |
OLD | NEW |