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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "core/include/fxcrt/fx_basic.h" | 10 #include "core/include/fxcrt/fx_basic.h" |
11 #include "core/include/fxcrt/fx_safe_types.h" | 11 #include "core/include/fxcrt/fx_safe_types.h" |
12 #include "third_party/base/numerics/safe_conversions.h" | 12 #include "third_party/base/numerics/safe_conversions.h" |
13 | 13 |
14 CFX_BinaryBuf::CFX_BinaryBuf() | 14 CFX_BinaryBuf::CFX_BinaryBuf() |
15 : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} | 15 : m_AllocStep(0), m_AllocSize(0), m_DataSize(0) {} |
16 | 16 |
17 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) | 17 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) |
18 : m_AllocStep(0), m_AllocSize(size), m_DataSize(size) { | 18 : m_AllocStep(0), m_AllocSize(size), m_DataSize(size) { |
19 m_pBuffer.reset(FX_Alloc(uint8_t, size)); | 19 m_pBuffer.reset(FX_Alloc(uint8_t, size)); |
20 } | 20 } |
21 | 21 |
| 22 CFX_BinaryBuf::~CFX_BinaryBuf() {} |
| 23 |
22 void CFX_BinaryBuf::Delete(int start_index, int count) { | 24 void CFX_BinaryBuf::Delete(int start_index, int count) { |
23 if (!m_pBuffer || start_index < 0 || count < 0 || count > m_DataSize || | 25 if (!m_pBuffer || start_index < 0 || count < 0 || count > m_DataSize || |
24 start_index > m_DataSize - count) { | 26 start_index > m_DataSize - count) { |
25 return; | 27 return; |
26 } | 28 } |
27 FXSYS_memmove(m_pBuffer.get() + start_index, | 29 FXSYS_memmove(m_pBuffer.get() + start_index, |
28 m_pBuffer.get() + start_index + count, | 30 m_pBuffer.get() + start_index + count, |
29 m_DataSize - start_index - count); | 31 m_DataSize - start_index - count); |
30 m_DataSize -= count; | 32 m_DataSize -= count; |
31 } | 33 } |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 if (bit_left) { | 359 if (bit_left) { |
358 result |= m_pData[byte_pos] >> (8 - bit_left); | 360 result |= m_pData[byte_pos] >> (8 - bit_left); |
359 } | 361 } |
360 m_BitPos += nBits; | 362 m_BitPos += nBits; |
361 return result; | 363 return result; |
362 } | 364 } |
363 | 365 |
364 CFX_FileBufferArchive::CFX_FileBufferArchive() | 366 CFX_FileBufferArchive::CFX_FileBufferArchive() |
365 : m_Length(0), m_pFile(nullptr) {} | 367 : m_Length(0), m_pFile(nullptr) {} |
366 | 368 |
| 369 CFX_FileBufferArchive::~CFX_FileBufferArchive() {} |
| 370 |
367 void CFX_FileBufferArchive::Clear() { | 371 void CFX_FileBufferArchive::Clear() { |
368 m_Length = 0; | 372 m_Length = 0; |
369 m_pBuffer.reset(); | 373 m_pBuffer.reset(); |
370 m_pFile = nullptr; | 374 m_pFile = nullptr; |
371 } | 375 } |
372 | 376 |
373 bool CFX_FileBufferArchive::Flush() { | 377 bool CFX_FileBufferArchive::Flush() { |
374 size_t nRemaining = m_Length; | 378 size_t nRemaining = m_Length; |
375 m_Length = 0; | 379 m_Length = 0; |
376 if (!m_pFile) | 380 if (!m_pFile) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 } | 419 } |
416 | 420 |
417 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { | 421 int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) { |
418 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); | 422 return AppendBlock(lpsz.GetPtr(), lpsz.GetLength()); |
419 } | 423 } |
420 | 424 |
421 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { | 425 void CFX_FileBufferArchive::AttachFile(IFX_StreamWrite* pFile) { |
422 FXSYS_assert(pFile); | 426 FXSYS_assert(pFile); |
423 m_pFile = pFile; | 427 m_pFile = pFile; |
424 } | 428 } |
OLD | NEW |