From 85444b0304f1c00b1b428ef72c336201269ada7a Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 17 Nov 2019 03:16:24 +0100 Subject: [PATCH] MO FIFO: limit read count to FIFO size --- sdrbase/dsp/samplemofifo.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sdrbase/dsp/samplemofifo.cpp b/sdrbase/dsp/samplemofifo.cpp index fd61115b4..dd140de37 100644 --- a/sdrbase/dsp/samplemofifo.cpp +++ b/sdrbase/dsp/samplemofifo.cpp @@ -83,7 +83,7 @@ void SampleMOFifo::readSync( { QMutexLocker mutexLocker(&m_mutex); unsigned int spaceLeft = m_size - m_readHead; - m_readCount += amount; + m_readCount = m_readCount + amount < m_size ? m_readCount + amount : m_size; // cannot exceed FIFO size if (amount <= spaceLeft) { @@ -146,7 +146,7 @@ void SampleMOFifo::writeSync( m_writeHead = remaining; } - m_readCount = amount < m_readCount ? m_readCount - amount : 0; + m_readCount = amount < m_readCount ? m_readCount - amount : 0; // cannot be less than 0 } void SampleMOFifo::readAsync( @@ -158,7 +158,7 @@ void SampleMOFifo::readAsync( { QMutexLocker mutexLocker(&m_mutex); unsigned int spaceLeft = m_size - m_vReadHead[stream]; - m_vReadCount[stream] += amount; + m_vReadCount[stream] = m_vReadCount[stream] + amount < m_size ? m_vReadCount[stream] + amount : m_size; // cannot exceed FIFO size if (amount <= spaceLeft) { @@ -225,7 +225,7 @@ void SampleMOFifo::writeAsync( //!< in place write with given amount m_vWriteHead[stream] = remaining; } - m_vReadCount[stream] = amount < m_vReadCount[stream] ? m_vReadCount[stream] - amount : 0; + m_vReadCount[stream] = amount < m_vReadCount[stream] ? m_vReadCount[stream] - amount : 0; // cannot be less than 0 } unsigned int SampleMOFifo::getSizePolicy(unsigned int sampleRate)