From 71be31bb61a4af808bd674b2cd4b70f7fa060676 Mon Sep 17 00:00:00 2001 From: RichardBarry <3073890+RichardBarry@users.noreply.github.com> Date: Sat, 10 Oct 2020 21:47:54 -0700 Subject: [PATCH] xStreamBufferSend() caps the maximum amount of data a stream buffer can send to the maximum capacity of the buffer - however the value to which the length is capped was wrong, and is correct by this check in. Likewise when sending to a message buffer if the send length is too long the block time is set to 0 to ensure the sending task does not wait indefinitely for the impossible send to complete - but the length check was wrong, and is corrected by this check in. (#195) --- stream_buffer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stream_buffer.c b/stream_buffer.c index c2d600ed5..9dd4ad04e 100644 --- a/stream_buffer.c +++ b/stream_buffer.c @@ -518,6 +518,10 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, size_t xRequiredSpace = xDataLengthBytes; TimeOut_t xTimeOut; + /* The maximum amount of space a stream buffer will ever report is its length + * minus 1. */ + const size_t xMaxReportedSpace = pxStreamBuffer->xLength - ( size_t ) 1; + configASSERT( pvTxData ); configASSERT( pxStreamBuffer ); @@ -534,7 +538,7 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, /* If this is a message buffer then it must be possible to write the * whole message. */ - if( xRequiredSpace > pxStreamBuffer->xLength ) + if( xRequiredSpace > xMaxReportedSpace ) { /* The message would not fit even if the entire buffer was empty, * so don't wait for space. */ @@ -550,9 +554,9 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer, /* If this is a stream buffer then it is acceptable to write only part * of the message to the buffer. Cap the length to the total length of * the buffer. */ - if( xRequiredSpace > pxStreamBuffer->xLength ) + if( xRequiredSpace > xMaxReportedSpace ) { - xRequiredSpace = pxStreamBuffer->xLength; + xRequiredSpace = xMaxReportedSpace; } else {