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

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

Issue 1145843005: Revert "Remove FX_Alloc() null checks now that it can't return NULL." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: 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 }
76 return new (pData) StringData(nLen, usableSize); 79 return new (pData) StringData(nLen, usableSize);
77 } 80 }
78 CFX_ByteString::~CFX_ByteString() 81 CFX_ByteString::~CFX_ByteString()
79 { 82 {
80 if (m_pData) { 83 if (m_pData) {
81 m_pData->Release(); 84 m_pData->Release();
82 } 85 }
83 } 86 }
84 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen) 87 CFX_ByteString::CFX_ByteString(FX_LPCSTR lpsz, FX_STRSIZE nLen)
85 { 88 {
(...skipping 1038 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 scale /= 10; 1127 scale /= 10;
1125 } 1128 }
1126 return buf_size; 1129 return buf_size;
1127 } 1130 }
1128 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision) 1131 CFX_ByteString CFX_ByteString::FormatFloat(FX_FLOAT d, int precision)
1129 { 1132 {
1130 FX_CHAR buf[32]; 1133 FX_CHAR buf[32];
1131 FX_STRSIZE len = FX_ftoa(d, buf); 1134 FX_STRSIZE len = FX_ftoa(d, buf);
1132 return CFX_ByteString(buf, len); 1135 return CFX_ByteString(buf, len);
1133 } 1136 }
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