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)

pull/199/head
RichardBarry 4 years ago committed by GitHub
parent 167ea16282
commit 71be31bb61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -518,6 +518,10 @@ size_t xStreamBufferSend( StreamBufferHandle_t xStreamBuffer,
size_t xRequiredSpace = xDataLengthBytes; size_t xRequiredSpace = xDataLengthBytes;
TimeOut_t xTimeOut; 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( pvTxData );
configASSERT( pxStreamBuffer ); 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 /* If this is a message buffer then it must be possible to write the
* whole message. */ * whole message. */
if( xRequiredSpace > pxStreamBuffer->xLength ) if( xRequiredSpace > xMaxReportedSpace )
{ {
/* The message would not fit even if the entire buffer was empty, /* The message would not fit even if the entire buffer was empty,
* so don't wait for space. */ * 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 /* 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 * of the message to the buffer. Cap the length to the total length of
* the buffer. */ * the buffer. */
if( xRequiredSpace > pxStreamBuffer->xLength ) if( xRequiredSpace > xMaxReportedSpace )
{ {
xRequiredSpace = pxStreamBuffer->xLength; xRequiredSpace = xMaxReportedSpace;
} }
else else
{ {

Loading…
Cancel
Save