From 8a3b48754e105f76442498ceb8c2796ebb1dec35 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 8 Nov 2024 19:48:41 +0100 Subject: [PATCH] util/ForeignFifoBuffer: use Read() in MoveBuffer() and Shift() --- src/util/ForeignFifoBuffer.hxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/ForeignFifoBuffer.hxx b/src/util/ForeignFifoBuffer.hxx index 17b501444..8aaa1794f 100644 --- a/src/util/ForeignFifoBuffer.hxx +++ b/src/util/ForeignFifoBuffer.hxx @@ -97,9 +97,10 @@ public: } void MoveBuffer(T *new_data, size_type new_capacity) noexcept { - assert(new_capacity >= tail - head); + const auto r = Read(); + assert(new_capacity >= r.size()); + std::move(r.begin(), r.end(), new_data); - std::move(data + head, data + tail, new_data); data = new_data; capacity = new_capacity; tail -= head; @@ -231,7 +232,8 @@ protected: assert(tail <= capacity); assert(tail >= head); - std::move(data + head, data + tail, data); + const auto r = Read(); + std::move(r.begin(), r.end(), data); tail -= head; head = 0;