From 37efe370e6816f4321655377dc6643b007c79ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 15 Feb 2024 09:53:26 +0100 Subject: [PATCH] Fix buffer growth in AllocAppender. The newly introduced "withAlloc" wrapper was not accepting arguments by reference, thus discarding the new array value returned by reallocate(). --- source/vibe/internal/array.d | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/vibe/internal/array.d b/source/vibe/internal/array.d index 63689ece..b158625e 100644 --- a/source/vibe/internal/array.d +++ b/source/vibe/internal/array.d @@ -185,7 +185,7 @@ struct AllocAppender(ArrayType : E[], E) { reserve(new_size - m_data.length + m_remaining.length); } - private auto withAlloc(string method, ARGS...)(ARGS args) + private auto withAlloc(string method, ARGS...)(auto ref ARGS args) { static if (is(RCIAllocator)) { if (!m_rcAlloc.isNull) return __traits(getMember, m_rcAlloc, method)(args); @@ -252,6 +252,14 @@ unittest { assert(app.data == "foo"); } +unittest { + auto app = AllocAppender!string(theAllocator); + app.reserve(3); + app.put("foo"); + app.put("bar"); + assert(app.data == "foobar"); +} + struct FixedAppender(ArrayType : E[], size_t NELEM, E) { alias ElemType = Unqual!E;