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

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

Issue 1142713005: Remove FX_Alloc() null checks now that it can't return NULL. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix missing FX_Alloc2D, check overflow on add, remove unused enum. Created 5 years, 7 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/fxcrt/fx_basic_array.cpp ('k') | core/src/fxcrt/fx_basic_buffer.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 <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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // Now round to an 8-byte boundary. We'd expect that this is the minimum 66 // Now round to an 8-byte boundary. We'd expect that this is the minimum
67 // granularity of any of the underlying allocators, so there may be cases 67 // granularity of any of the underlying allocators, so there may be cases
68 // where we can save a re-alloc when adding a few characters to a string 68 // where we can save a re-alloc when adding a few characters to a string
69 // by using this otherwise wasted space. 69 // by using this otherwise wasted space.
70 nSize += 7; 70 nSize += 7;
71 int totalSize = nSize.ValueOrDie() & ~7; 71 int totalSize = nSize.ValueOrDie() & ~7;
72 int usableSize = totalSize - overhead; 72 int usableSize = totalSize - overhead;
73 FXSYS_assert(usableSize >= nLen); 73 FXSYS_assert(usableSize >= nLen);
74 74
75 void* pData = FX_Alloc(FX_BYTE, totalSize); 75 void* pData = FX_Alloc(FX_BYTE, totalSize);
76 if (!pData) {
77 return NULL;
78 }
79 return new (pData) StringData(nLen, usableSize); 76 return new (pData) StringData(nLen, usableSize);
80 } 77 }
81 CFX_ByteString::~CFX_ByteString() 78 CFX_ByteString::~CFX_ByteString()
82 { 79 {
83 if (m_pData) { 80 if (m_pData) {
84 m_pData->Release(); 81 m_pData->Release();
85 } 82 }
86 } 83 }
87 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) 84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen)
88 { 85 {
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 scale /= 10; 1124 scale /= 10;
1128 } 1125 }
1129 return buf_size; 1126 return buf_size;
1130 } 1127 }
1131 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) 1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision)
1132 { 1129 {
1133 FX_CHAR buf[32]; 1130 FX_CHAR buf[32];
1134 FX_STRSIZE len = FX_ftoa(d, buf); 1131 FX_STRSIZE len = FX_ftoa(d, buf);
1135 return CFX_ByteString(buf, len); 1132 return CFX_ByteString(buf, len);
1136 } 1133 }
OLDNEW
« no previous file with comments | « core/src/fxcrt/fx_basic_array.cpp ('k') | core/src/fxcrt/fx_basic_buffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698