[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 <alexmarkov@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
diff --git a/runtime/platform/text_buffer.cc b/runtime/platform/text_buffer.cc
index c1fc58a..ed2c640 100644
--- a/runtime/platform/text_buffer.cc
+++ b/runtime/platform/text_buffer.cc
@@ -135,7 +135,7 @@
 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<char*>(realloc(buf_, new_size));
     if (new_buf == NULL) {
       OUT_OF_MEMORY();