From b613707d07767a51c9dadf470fe86bb37fd79110 Mon Sep 17 00:00:00 2001 From: Djordje Nedic Date: Thu, 7 Dec 2023 14:20:37 +0100 Subject: [PATCH] fix: Fix a linear space calculation bug in BipartiteBuf This fixes a bug where the linear space until the end of the buffer was not calculated correctly. In debug builds, an assert would trigger however for release there could be data corruption. --- lockfree/spsc/bipartite_buf_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lockfree/spsc/bipartite_buf_impl.hpp b/lockfree/spsc/bipartite_buf_impl.hpp index da9a5c4..28fbd20 100644 --- a/lockfree/spsc/bipartite_buf_impl.hpp +++ b/lockfree/spsc/bipartite_buf_impl.hpp @@ -60,7 +60,7 @@ T *BipartiteBuf::WriteAcquire(const size_t free_required) { const size_t r = _r.load(std::memory_order_acquire); const size_t free = CalcFree(w, r); - const size_t linear_space = size - r; + const size_t linear_space = size - w; const size_t linear_free = std::min(free, linear_space); /* Try to find enough linear space until the end of the buffer */