Skip to content

Commit 71be31b

Browse files
authored
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)
1 parent 167ea16 commit 71be31b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

stream_buffer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
518518
size_t xRequiredSpace = xDataLengthBytes;
519519
TimeOut_t xTimeOut;
520520

521+
/* The maximum amount of space a stream buffer will ever report is its length
522+
* minus 1. */
523+
const size_t xMaxReportedSpace = pxStreamBuffer->xLength - ( size_t ) 1;
524+
521525
configASSERT( pvTxData );
522526
configASSERT( pxStreamBuffer );
523527

@@ -534,7 +538,7 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
534538

535539
/* If this is a message buffer then it must be possible to write the
536540
* whole message. */
537-
if( xRequiredSpace > pxStreamBuffer->xLength )
541+
if( xRequiredSpace > xMaxReportedSpace )
538542
{
539543
/* The message would not fit even if the entire buffer was empty,
540544
* so don't wait for space. */
@@ -550,9 +554,9 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
550554
/* If this is a stream buffer then it is acceptable to write only part
551555
* of the message to the buffer. Cap the length to the total length of
552556
* the buffer. */
553-
if( xRequiredSpace > pxStreamBuffer->xLength )
557+
if( xRequiredSpace > xMaxReportedSpace )
554558
{
555-
xRequiredSpace = pxStreamBuffer->xLength;
559+
xRequiredSpace = xMaxReportedSpace;
556560
}
557561
else
558562
{

0 commit comments

Comments
 (0)