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

Side by Side Diff: runtime/platform/text_buffer.cc

Issue 2418323002: Make fatal out of memory messages uniform. (Closed)
Patch Set: macro Created 4 years, 2 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 | « runtime/platform/hashmap.cc ('k') | runtime/vm/clustered_snapshot.cc » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/text_buffer.h" 5 #include "platform/text_buffer.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 #include "platform/utils.h" 9 #include "platform/utils.h"
10 #include "vm/os.h" 10 #include "vm/os.h"
11 #include "vm/unicode.h" 11 #include "vm/unicode.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 TextBuffer::TextBuffer(intptr_t buf_size) { 15 TextBuffer::TextBuffer(intptr_t buf_size) {
16 ASSERT(buf_size > 0); 16 ASSERT(buf_size > 0);
17 buf_ = reinterpret_cast<char*>(malloc(buf_size)); 17 buf_ = reinterpret_cast<char*>(malloc(buf_size));
18 if (buf_ == NULL) {
19 OUT_OF_MEMORY();
20 }
18 buf_size_ = buf_size; 21 buf_size_ = buf_size;
19 Clear(); 22 Clear();
20 } 23 }
21 24
22 25
23 TextBuffer::~TextBuffer() { 26 TextBuffer::~TextBuffer() {
24 free(buf_); 27 free(buf_);
25 buf_ = NULL; 28 buf_ = NULL;
26 } 29 }
27 30
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void TextBuffer::EnsureCapacity(intptr_t len) { 148 void TextBuffer::EnsureCapacity(intptr_t len) {
146 intptr_t remaining = buf_size_ - msg_len_; 149 intptr_t remaining = buf_size_ - msg_len_;
147 if (remaining <= len) { 150 if (remaining <= len) {
148 const int kBufferSpareCapacity = 64; // Somewhat arbitrary. 151 const int kBufferSpareCapacity = 64; // Somewhat arbitrary.
149 // TODO(turnidge): do we need to guard against overflow or other 152 // TODO(turnidge): do we need to guard against overflow or other
150 // security issues here? Text buffers are used by the debugger 153 // security issues here? Text buffers are used by the debugger
151 // to send user-controlled data (e.g. values of string variables) to 154 // to send user-controlled data (e.g. values of string variables) to
152 // the debugger front-end. 155 // the debugger front-end.
153 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity; 156 intptr_t new_size = buf_size_ + len + kBufferSpareCapacity;
154 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size)); 157 char* new_buf = reinterpret_cast<char*>(realloc(buf_, new_size));
155 ASSERT(new_buf != NULL); 158 if (new_buf == NULL) {
159 OUT_OF_MEMORY();
160 }
156 buf_ = new_buf; 161 buf_ = new_buf;
157 buf_size_ = new_size; 162 buf_size_ = new_size;
158 } 163 }
159 } 164 }
160 165
161 } // namespace dart 166 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/platform/hashmap.cc ('k') | runtime/vm/clustered_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698