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 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); | 8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_LPSTR buf); |
9 CFX_BinaryBuf::CFX_BinaryBuf() | 9 CFX_BinaryBuf::CFX_BinaryBuf() |
10 : m_AllocStep(0) | 10 : m_AllocStep(0) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } else { | 81 } else { |
82 alloc_step = m_AllocStep; | 82 alloc_step = m_AllocStep; |
83 } | 83 } |
84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; | 84 new_size = (new_size + alloc_step - 1) / alloc_step * alloc_step; |
85 FX_LPBYTE pNewBuffer = m_pBuffer; | 85 FX_LPBYTE pNewBuffer = m_pBuffer; |
86 if (pNewBuffer) { | 86 if (pNewBuffer) { |
87 pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size); | 87 pNewBuffer = FX_Realloc(FX_BYTE, m_pBuffer, new_size); |
88 } else { | 88 } else { |
89 pNewBuffer = FX_Alloc(FX_BYTE, new_size); | 89 pNewBuffer = FX_Alloc(FX_BYTE, new_size); |
90 } | 90 } |
91 m_pBuffer = pNewBuffer; | 91 if (pNewBuffer) { |
92 m_AllocSize = new_size; | 92 m_pBuffer = pNewBuffer; |
| 93 m_AllocSize = new_size; |
| 94 } |
93 } | 95 } |
94 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) | 96 void CFX_BinaryBuf::CopyData(const void* pStr, FX_STRSIZE size) |
95 { | 97 { |
96 if (size == 0) { | 98 if (size == 0) { |
97 m_DataSize = 0; | 99 m_DataSize = 0; |
98 return; | 100 return; |
99 } | 101 } |
100 if (m_AllocSize < size) { | 102 if (m_AllocSize < size) { |
101 ExpandBuf(size - m_DataSize); | 103 ExpandBuf(size - m_DataSize); |
102 } | 104 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 m_Length = 0; | 449 m_Length = 0; |
448 return bRet; | 450 return bRet; |
449 } | 451 } |
450 FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) | 452 FX_INT32 IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) |
451 { | 453 { |
452 if (!pBuf || size < 1) { | 454 if (!pBuf || size < 1) { |
453 return 0; | 455 return 0; |
454 } | 456 } |
455 if (!m_pBuffer) { | 457 if (!m_pBuffer) { |
456 m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); | 458 m_pBuffer = FX_Alloc(FX_BYTE, m_BufSize); |
| 459 if (!m_pBuffer) { |
| 460 return -1; |
| 461 } |
457 } | 462 } |
458 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; | 463 FX_LPBYTE buffer = (FX_LPBYTE)pBuf; |
459 FX_STRSIZE temp_size = (FX_STRSIZE)size; | 464 FX_STRSIZE temp_size = (FX_STRSIZE)size; |
460 while (temp_size > 0) { | 465 while (temp_size > 0) { |
461 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); | 466 FX_STRSIZE buf_size = FX_MIN(m_BufSize - m_Length, (FX_STRSIZE)temp_size
); |
462 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); | 467 FXSYS_memcpy32(m_pBuffer + m_Length, buffer, buf_size); |
463 m_Length += buf_size; | 468 m_Length += buf_size; |
464 if (m_Length == m_BufSize) { | 469 if (m_Length == m_BufSize) { |
465 if (!Flush()) { | 470 if (!Flush()) { |
466 return -1; | 471 return -1; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) | 554 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) |
550 { | 555 { |
551 if (!m_pFile) { | 556 if (!m_pFile) { |
552 return FALSE; | 557 return FALSE; |
553 } | 558 } |
554 if (!pBuf || size < 1) { | 559 if (!pBuf || size < 1) { |
555 return TRUE; | 560 return TRUE; |
556 } | 561 } |
557 return m_pFile->WriteBlock(pBuf, size); | 562 return m_pFile->WriteBlock(pBuf, size); |
558 } | 563 } |
OLD | NEW |