| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |