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)

diff --git a/stream_buffer.c b/stream_buffer.c
index c2d600e..9dd4ad0 100644
--- a/stream_buffer.c
+++ b/stream_buffer.c
@@ -518,6 +518,10 @@
     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 @@
 

         /* 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 @@
         /* 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

         {