Index: src/utils.cc |
diff --git a/src/utils.cc b/src/utils.cc |
index 7e8c088dd492dc527e9803204ff6de9b2f5ab7d2..71eaea55d261989a58af4381e20b147fc1b3ddb0 100644 |
--- a/src/utils.cc |
+++ b/src/utils.cc |
@@ -46,7 +46,7 @@ void SimpleStringBuilder::AddString(const char* s) { |
void SimpleStringBuilder::AddSubstring(const char* s, int n) { |
- ASSERT(!is_finalized() && position_ + n < buffer_.length()); |
+ ASSERT(!is_finalized() && position_ + n <= buffer_.length()); |
ASSERT(static_cast<size_t>(n) <= strlen(s)); |
memcpy(&buffer_[position_], s, n * kCharSize); |
position_ += n; |
@@ -79,7 +79,13 @@ void SimpleStringBuilder::AddDecimalInteger(int32_t value) { |
char* SimpleStringBuilder::Finalize() { |
- ASSERT(!is_finalized() && position_ < buffer_.length()); |
+ ASSERT(!is_finalized() && position_ <= buffer_.length()); |
+ // If there is no space for null termination, overwrite last character. |
+ if (position_ == buffer_.length()) { |
+ position_--; |
+ // Print ellipsis. |
+ for (int i = 3; i > 0 && position_ > i; --i) buffer_[position_ - i] = '.'; |
+ } |
buffer_[position_] = '\0'; |
// Make sure nobody managed to add a 0-character to the |
// buffer while building the string. |