From 57f810420e0870e3f7d036d95a4057c3a052f7fd Mon Sep 17 00:00:00 2001 From: Odysseas Georgoudis Date: Mon, 17 Apr 2023 22:53:12 +0100 Subject: [PATCH] cap capacity --- quill/include/quill/detail/spsc_queue/UnboundedQueue.h | 4 +++- quill/src/detail/backend/TransitEventBuffer.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/quill/include/quill/detail/spsc_queue/UnboundedQueue.h b/quill/include/quill/detail/spsc_queue/UnboundedQueue.h index 5ae52fa6..9bedda1c 100644 --- a/quill/include/quill/detail/spsc_queue/UnboundedQueue.h +++ b/quill/include/quill/detail/spsc_queue/UnboundedQueue.h @@ -102,7 +102,9 @@ class UnboundedQueue } // bounded queue max power of 2 capacity since uint32_t type is used to hold the value 2147483648 bytes - constexpr uint64_t max_bounded_queue_capacity = (std::numeric_limits::max() >> 1) + 1; + constexpr uint64_t max_bounded_queue_capacity = + (std::numeric_limits::max() >> 1) + 1; + if (QUILL_UNLIKELY(capacity > max_bounded_queue_capacity)) { if ((nbytes + 1) > max_bounded_queue_capacity) diff --git a/quill/src/detail/backend/TransitEventBuffer.cpp b/quill/src/detail/backend/TransitEventBuffer.cpp index 875a8fac..5c62e79e 100644 --- a/quill/src/detail/backend/TransitEventBuffer.cpp +++ b/quill/src/detail/backend/TransitEventBuffer.cpp @@ -134,9 +134,12 @@ TransitEvent* UnboundedTransitEventBuffer::back() noexcept { // buffer doesn't have enough space uint64_t capacity = static_cast(_writer->transit_buffer.capacity()) * 2ull; - if (QUILL_UNLIKELY(capacity > std::numeric_limits::max())) + constexpr uint64_t max_bounded_queue_capacity = + (std::numeric_limits::max() >> 1) + 1; + + if (QUILL_UNLIKELY(capacity > max_bounded_queue_capacity)) { - capacity = std::numeric_limits::max(); + capacity = max_bounded_queue_capacity; } auto new_node = new Node{static_cast(capacity)};