From 52dca859c7ad32ac0869f75326ea82731d7d2271 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 19 Dec 2013 10:30:26 +0100 Subject: [PATCH] util/PeakBuffer: use IsEmpty() instead of IsNull() The DynamicFifoBuffer methods never return nullptr when the buffer is empty or full; instead, they return an empty buffer. This bug caused an endless loop. --- src/event/FullyBufferedSocket.cxx | 2 +- src/util/PeakBuffer.cxx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/event/FullyBufferedSocket.cxx b/src/event/FullyBufferedSocket.cxx index e7869cd66..375132e34 100644 --- a/src/event/FullyBufferedSocket.cxx +++ b/src/event/FullyBufferedSocket.cxx @@ -60,7 +60,7 @@ FullyBufferedSocket::Flush() assert(IsDefined()); const auto data = output.Read(); - if (data.IsNull()) { + if (data.IsEmpty()) { IdleMonitor::Cancel(); CancelWrite(); return true; diff --git a/src/util/PeakBuffer.cxx b/src/util/PeakBuffer.cxx index c66218043..5e86503e8 100644 --- a/src/util/PeakBuffer.cxx +++ b/src/util/PeakBuffer.cxx @@ -43,13 +43,13 @@ PeakBuffer::Read() const { if (normal_buffer != nullptr) { const auto p = normal_buffer->Read(); - if (!p.IsNull()) + if (!p.IsEmpty()) return p.ToVoid(); } if (peak_buffer != nullptr) { const auto p = peak_buffer->Read(); - if (!p.IsNull()) + if (!p.IsEmpty()) return p.ToVoid(); } @@ -85,7 +85,7 @@ AppendTo(DynamicFifoBuffer &buffer, const void *data, size_t length) do { const auto p = buffer.Write(); - if (p.IsNull()) + if (p.IsEmpty()) break; const size_t nbytes = std::min(length, p.size);