From aceefaf8460b6466f13b63293e3a0f05621b6851 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Wed, 1 May 2019 22:26:41 +0000 Subject: [PATCH] [dart/vm]: fix bug in TextBuffer capacity Rationale: Ensuring capacity computation was off by one (due to trailing '\0') if the initial buffer size was zero. Granted, this can only happen after a Steal(), but since API did not exclude reuse after this operation, it is better to just handle this than crash. https://github.com/dart-lang/sdk/issues/36818 Change-Id: I4e404c4361da03e24364280fb01a308fbf7ace6c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/100991 Reviewed-by: Alexander Markov Commit-Queue: Aart Bik --- runtime/platform/text_buffer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/platform/text_buffer.cc b/runtime/platform/text_buffer.cc index c1fc58ad43d..ed2c6400770 100644 --- a/runtime/platform/text_buffer.cc +++ b/runtime/platform/text_buffer.cc @@ -135,7 +135,7 @@ void TextBuffer::AddEscapedString(const char* s) { void TextBuffer::EnsureCapacity(intptr_t len) { intptr_t remaining = buf_size_ - msg_len_; if (remaining <= len) { - intptr_t new_size = buf_size_ + Utils::Maximum(buf_size_, len); + intptr_t new_size = buf_size_ + Utils::Maximum(buf_size_, len + 1); char* new_buf = reinterpret_cast(realloc(buf_, new_size)); if (new_buf == NULL) { OUT_OF_MEMORY();