From f023db863815e1c9b8829abbcac3ed04eff94e9f Mon Sep 17 00:00:00 2001 From: Walther Chen Date: Sat, 6 Dec 2025 23:57:11 +0700 Subject: [PATCH] fix ByteBuffer.grow (#2622) * fix ByteBuffer.grow --------- Co-authored-by: Christoffer Lerno --- lib/std/io/stream/bytebuffer.c3 | 2 +- releasenotes.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/io/stream/bytebuffer.c3 b/lib/std/io/stream/bytebuffer.c3 index e550befdf..a81d886e5 100644 --- a/lib/std/io/stream/bytebuffer.c3 +++ b/lib/std/io/stream/bytebuffer.c3 @@ -130,7 +130,7 @@ fn usz? ByteBuffer.available(&self) @inline @dynamic fn void ByteBuffer.grow(&self, usz n) { - n = math::next_power_of_2(n); + n = math::next_power_of_2(self.bytes.len + n); char* p = allocator::realloc(self.allocator, self.bytes, n); self.bytes = p[:n]; } diff --git a/releasenotes.md b/releasenotes.md index 41898e94d..02758786d 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -9,6 +9,7 @@ - Regression with npot vector in struct triggering an assert #2219. - Casting bitstruct to wider base type should be single step #2616. - Optional does not play well with bit ops #2618. +- `Bytebuffer.grow` was broken #2622. ### Stdlib changes