Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: core/src/fxcrt/fx_basic_buffer.cpp

Issue 1297713003: Don't bother checking pointers before delete[] and FX_Free(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_jpeg.cpp ('k') | core/src/fxcrt/fx_basic_maps.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_CHAR* buf); 8 FX_STRSIZE FX_ftoa(FX_FLOAT f, FX_CHAR* buf);
9 CFX_BinaryBuf::CFX_BinaryBuf() 9 CFX_BinaryBuf::CFX_BinaryBuf()
10 : m_AllocStep(0), m_pBuffer(NULL), m_DataSize(0), m_AllocSize(0) {} 10 : m_AllocStep(0), m_pBuffer(NULL), m_DataSize(0), m_AllocSize(0) {}
11 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size) 11 CFX_BinaryBuf::CFX_BinaryBuf(FX_STRSIZE size)
12 : m_AllocStep(0), m_DataSize(size), m_AllocSize(size) { 12 : m_AllocStep(0), m_DataSize(size), m_AllocSize(size) {
13 m_pBuffer = FX_Alloc(uint8_t, size); 13 m_pBuffer = FX_Alloc(uint8_t, size);
14 } 14 }
15 CFX_BinaryBuf::~CFX_BinaryBuf() { 15 CFX_BinaryBuf::~CFX_BinaryBuf() {
16 if (m_pBuffer) { 16 FX_Free(m_pBuffer);
17 FX_Free(m_pBuffer);
18 }
19 } 17 }
20 void CFX_BinaryBuf::Delete(int start_index, int count) { 18 void CFX_BinaryBuf::Delete(int start_index, int count) {
21 if (!m_pBuffer || start_index < 0 || start_index + count > m_DataSize) { 19 if (!m_pBuffer || start_index < 0 || start_index + count > m_DataSize) {
22 return; 20 return;
23 } 21 }
24 FXSYS_memmove(m_pBuffer + start_index, m_pBuffer + start_index + count, 22 FXSYS_memmove(m_pBuffer + start_index, m_pBuffer + start_index + count,
25 m_DataSize - start_index - count); 23 m_DataSize - start_index - count);
26 m_DataSize -= count; 24 m_DataSize -= count;
27 } 25 }
28 void CFX_BinaryBuf::Clear() { 26 void CFX_BinaryBuf::Clear() {
29 m_DataSize = 0; 27 m_DataSize = 0;
30 } 28 }
31 void CFX_BinaryBuf::DetachBuffer() { 29 void CFX_BinaryBuf::DetachBuffer() {
32 m_DataSize = 0; 30 m_DataSize = 0;
33 m_pBuffer = NULL; 31 m_pBuffer = NULL;
34 m_AllocSize = 0; 32 m_AllocSize = 0;
35 } 33 }
36 void CFX_BinaryBuf::AttachData(void* buffer, FX_STRSIZE size) { 34 void CFX_BinaryBuf::AttachData(void* buffer, FX_STRSIZE size) {
37 if (m_pBuffer) { 35 FX_Free(m_pBuffer);
38 FX_Free(m_pBuffer);
39 }
40 m_DataSize = size; 36 m_DataSize = size;
41 m_pBuffer = (uint8_t*)buffer; 37 m_pBuffer = (uint8_t*)buffer;
42 m_AllocSize = size; 38 m_AllocSize = size;
43 } 39 }
44 void CFX_BinaryBuf::TakeOver(CFX_BinaryBuf& other) { 40 void CFX_BinaryBuf::TakeOver(CFX_BinaryBuf& other) {
45 AttachData(other.GetBuffer(), other.GetSize()); 41 AttachData(other.GetBuffer(), other.GetSize());
46 other.DetachBuffer(); 42 other.DetachBuffer();
47 } 43 }
48 void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) { 44 void CFX_BinaryBuf::EstimateSize(FX_STRSIZE size, FX_STRSIZE step) {
49 m_AllocStep = step; 45 m_AllocStep = step;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (bit_left) { 247 if (bit_left) {
252 result |= m_pData[byte_pos] >> (8 - bit_left); 248 result |= m_pData[byte_pos] >> (8 - bit_left);
253 } 249 }
254 m_BitPos += nBits; 250 m_BitPos += nBits;
255 return result; 251 return result;
256 } 252 }
257 IFX_BufferArchive::IFX_BufferArchive(FX_STRSIZE size) 253 IFX_BufferArchive::IFX_BufferArchive(FX_STRSIZE size)
258 : m_BufSize(size), m_pBuffer(NULL), m_Length(0) {} 254 : m_BufSize(size), m_pBuffer(NULL), m_Length(0) {}
259 void IFX_BufferArchive::Clear() { 255 void IFX_BufferArchive::Clear() {
260 m_Length = 0; 256 m_Length = 0;
261 if (m_pBuffer) { 257 FX_Free(m_pBuffer);
262 FX_Free(m_pBuffer); 258 m_pBuffer = NULL;
263 m_pBuffer = NULL;
264 }
265 } 259 }
266 FX_BOOL IFX_BufferArchive::Flush() { 260 FX_BOOL IFX_BufferArchive::Flush() {
267 FX_BOOL bRet = DoWork(m_pBuffer, m_Length); 261 FX_BOOL bRet = DoWork(m_pBuffer, m_Length);
268 m_Length = 0; 262 m_Length = 0;
269 return bRet; 263 return bRet;
270 } 264 }
271 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) { 265 int32_t IFX_BufferArchive::AppendBlock(const void* pBuf, size_t size) {
272 if (!pBuf || size < 1) { 266 if (!pBuf || size < 1) {
273 return 0; 267 return 0;
274 } 268 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 323 }
330 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) { 324 FX_BOOL CFX_FileBufferArchive::DoWork(const void* pBuf, size_t size) {
331 if (!m_pFile) { 325 if (!m_pFile) {
332 return FALSE; 326 return FALSE;
333 } 327 }
334 if (!pBuf || size < 1) { 328 if (!pBuf || size < 1) {
335 return TRUE; 329 return TRUE;
336 } 330 }
337 return m_pFile->WriteBlock(pBuf, size); 331 return m_pFile->WriteBlock(pBuf, size);
338 } 332 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_jpeg.cpp ('k') | core/src/fxcrt/fx_basic_maps.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698