mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-13 08:17:44 -04:00
Demo/Common: fix divide by zero possibility and non-used return values (#1370)
* Demo/Common: fix divide by zero possibility and non-used return values - In TimerDemo.c fix possible divide by zero in "xMaxBlockTimeUsedByTheseTests / xCycleFrequency". - Move this code in TimerDemo.c into if-clause where it is actually used. - In Minimal/StreamBufferDemo.c and Minimal/TaskNotify.c avoid unused return values. Signed-off-by: Florian La Roche <Florian.LaRoche@gmail.com> Co-authored-by: Kody Stribrny <kstribrn@amazon.com>
This commit is contained in:
parent
e933faf3ee
commit
62195136d1
3 changed files with 12 additions and 9 deletions
|
@ -560,7 +560,7 @@ static void prvSingleTaskTests( StreamBufferHandle_t xStreamBuffer )
|
|||
/* Ensure data was written as expected even when there was an attempt to
|
||||
* write more than was available. This also tries to read more bytes than are
|
||||
* available. */
|
||||
xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
|
||||
xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
|
||||
prvCheckExpectedState( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
|
||||
prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
|
||||
prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );
|
||||
|
|
|
@ -242,6 +242,7 @@ static void prvSingleTaskTests( void )
|
|||
configASSERT( xReturned == pdPASS );
|
||||
( void ) xReturned; /* In case configASSERT() is not defined. */
|
||||
xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
|
||||
configASSERT( xReturned == pdPASS );
|
||||
configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
|
||||
( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */
|
||||
|
||||
|
|
|
@ -230,8 +230,10 @@ static void prvTimerTestTask( void * pvParameters )
|
|||
BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
|
||||
{
|
||||
static uint32_t ulLastLoopCounter = 0UL;
|
||||
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
|
||||
static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
|
||||
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
|
||||
|
||||
configASSERT( xCycleFrequency != 0UL );
|
||||
|
||||
if( xLastCycleFrequency != xCycleFrequency )
|
||||
{
|
||||
|
@ -241,17 +243,17 @@ BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
|
|||
xLastCycleFrequency = xCycleFrequency;
|
||||
}
|
||||
|
||||
/* Calculate the maximum number of times that it is permissible for this
|
||||
* function to be called without ulLoopCounter being incremented. This is
|
||||
* necessary because the tests in this file block for extended periods, and the
|
||||
* block period might be longer than the time between calls to this function. */
|
||||
xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
|
||||
xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
|
||||
|
||||
/* If the demo task is still running then the loop counter is expected to
|
||||
* have incremented every xLoopCounterIncrementTimeMax calls. */
|
||||
if( ulLastLoopCounter == ulLoopCounter )
|
||||
{
|
||||
/* Calculate the maximum number of times that it is permissible for this
|
||||
* function to be called without ulLoopCounter being incremented. This is
|
||||
* necessary because the tests in this file block for extended periods, and the
|
||||
* block period might be longer than the time between calls to this function. */
|
||||
xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
|
||||
xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
|
||||
|
||||
xIterationsWithoutCounterIncrement++;
|
||||
|
||||
if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue