]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/stream_buffer.c
Introduce sbBYTES_TO_STORE_MESSAGE_LENGTH to allow the number of bytes used to hold...
[freertos] / FreeRTOS / Source / stream_buffer.c
index 9e518907adffa68f9ce855825e8a1f86a179e6ce..ed8baef91b1f0c95fa9b245a0bf7282d1132bfa8 100644 (file)
@@ -129,7 +129,7 @@ that uses task notifications. */
 /*lint -restore (9026) */\r
 \r
 /* The number of bytes used to hold the length of a message in the buffer. */\r
-#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( size_t ) )\r
+#define sbBYTES_TO_STORE_MESSAGE_LENGTH ( sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) )\r
 \r
 /* Bits stored in the ucFlags field of the stream buffer. */\r
 #define sbFLAGS_IS_MESSAGE_BUFFER              ( ( uint8_t ) 1 ) /* Set if the stream buffer was created as a message buffer, in which case it holds discrete messages rather than a stream. */\r
@@ -504,6 +504,9 @@ TimeOut_t xTimeOut;
        if( ( pxStreamBuffer->ucFlags & sbFLAGS_IS_MESSAGE_BUFFER ) != ( uint8_t ) 0 )\r
        {\r
                xRequiredSpace += sbBYTES_TO_STORE_MESSAGE_LENGTH;\r
+\r
+               /* Overflow? */\r
+               configASSERT( xRequiredSpace > xDataLengthBytes );\r
        }\r
        else\r
        {\r
@@ -906,6 +909,9 @@ size_t xOriginalTail, xReceivedLength, xNextMessageLength;
                returned to its prior state if the length of the message is too\r
                large for the provided buffer. */\r
                xOriginalTail = pxStreamBuffer->xTail;\r
+               /* Ensure xNextMessageLength is cleared to 0 in case\r
+               sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) != sizeof( size_t ). */\r
+               xNextMessageLength = 0;\r
                ( void ) prvReadBytesFromBuffer( pxStreamBuffer, ( uint8_t * ) &xNextMessageLength, xBytesToStoreMessageLength, xBytesAvailable );\r
 \r
                /* Reduce the number of bytes available by the number of bytes just\r