Skip to content

Commit

Permalink
Fix buffer growth in AllocAppender.
Browse files Browse the repository at this point in the history
The newly introduced "withAlloc" wrapper was not accepting arguments by reference, thus discarding the new array value returned by reallocate().
  • Loading branch information
s-ludwig committed Feb 15, 2024
1 parent 7823db6 commit 37efe37
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion source/vibe/internal/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 37efe37

Please sign in to comment.