Skip to content

Commit 6219513

Browse files
Demo/Common: fix divide by zero possibility and non-used return values (FreeRTOS#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 <[email protected]> Co-authored-by: Kody Stribrny <[email protected]>
1 parent e933faf commit 6219513

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ static void prvSingleTaskTests( StreamBufferHandle_t xStreamBuffer )
560560
/* Ensure data was written as expected even when there was an attempt to
561561
* write more than was available. This also tries to read more bytes than are
562562
* available. */
563-
xReturned = xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
563+
xStreamBufferReceive( xStreamBuffer, ( void * ) pucFullBuffer, xFullBufferSize, xMinimalBlockTime );
564564
prvCheckExpectedState( memcmp( ( const void * ) pucFullBuffer, ( const void * ) pc54ByteString, sbSTREAM_BUFFER_LENGTH_BYTES ) == 0 );
565565
prvCheckExpectedState( xStreamBufferIsFull( xStreamBuffer ) == pdFALSE );
566566
prvCheckExpectedState( xStreamBufferIsEmpty( xStreamBuffer ) == pdTRUE );

FreeRTOS/Demo/Common/Minimal/TaskNotify.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ static void prvSingleTaskTests( void )
242242
configASSERT( xReturned == pdPASS );
243243
( void ) xReturned; /* In case configASSERT() is not defined. */
244244
xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );
245+
configASSERT( xReturned == pdPASS );
245246
configASSERT( ulNotifiedValue == ulSecondNotifiedValueConst );
246247
( void ) ulNotifiedValue; /* In case configASSERT() is not defined. */
247248

FreeRTOS/Demo/Common/Minimal/TimerDemo.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ static void prvTimerTestTask( void * pvParameters )
230230
BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
231231
{
232232
static uint32_t ulLastLoopCounter = 0UL;
233-
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
234233
static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCycleFrequency;
234+
TickType_t xMaxBlockTimeUsedByTheseTests, xLoopCounterIncrementTimeMax;
235+
236+
configASSERT( xCycleFrequency != 0UL );
235237

236238
if( xLastCycleFrequency != xCycleFrequency )
237239
{
@@ -241,17 +243,17 @@ BaseType_t xAreTimerDemoTasksStillRunning( TickType_t xCycleFrequency )
241243
xLastCycleFrequency = xCycleFrequency;
242244
}
243245

244-
/* Calculate the maximum number of times that it is permissible for this
245-
* function to be called without ulLoopCounter being incremented. This is
246-
* necessary because the tests in this file block for extended periods, and the
247-
* block period might be longer than the time between calls to this function. */
248-
xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
249-
xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
250-
251246
/* If the demo task is still running then the loop counter is expected to
252247
* have incremented every xLoopCounterIncrementTimeMax calls. */
253248
if( ulLastLoopCounter == ulLoopCounter )
254249
{
250+
/* Calculate the maximum number of times that it is permissible for this
251+
* function to be called without ulLoopCounter being incremented. This is
252+
* necessary because the tests in this file block for extended periods, and the
253+
* block period might be longer than the time between calls to this function. */
254+
xMaxBlockTimeUsedByTheseTests = ( ( TickType_t ) configTIMER_QUEUE_LENGTH ) * xBasePeriod;
255+
xLoopCounterIncrementTimeMax = ( xMaxBlockTimeUsedByTheseTests / xCycleFrequency ) + 1;
256+
255257
xIterationsWithoutCounterIncrement++;
256258

257259
if( xIterationsWithoutCounterIncrement > xLoopCounterIncrementTimeMax )

0 commit comments

Comments
 (0)