score: Accept NULL pointer in _Freechain_Put()

With this a _Freechain_Put( _Freechain_Get() ) works always.
This commit is contained in:
Sebastian Huber
2015-06-25 06:50:04 +02:00
parent fdb45d6b26
commit f59f2fe93e
3 changed files with 7 additions and 2 deletions

View File

@@ -93,7 +93,8 @@ void *_Freechain_Get(
* @brief Puts a node back onto the freechain. * @brief Puts a node back onto the freechain.
* *
* @param[in] freechain The freechain control. * @param[in] freechain The freechain control.
* @param[in] node The node to put back. * @param[in] node The node to put back. The node may be @c NULL, in this case
* the function does nothing.
*/ */
void _Freechain_Put( void _Freechain_Put(
Freechain_Control *freechain, Freechain_Control *freechain,

View File

@@ -74,5 +74,7 @@ void *_Freechain_Get(
void _Freechain_Put( Freechain_Control *freechain, void *node ) void _Freechain_Put( Freechain_Control *freechain, void *node )
{ {
if ( node != NULL ) {
_Chain_Prepend_unprotected( &freechain->Free, node ); _Chain_Prepend_unprotected( &freechain->Free, node );
} }
}

View File

@@ -40,6 +40,8 @@ static rtems_task Init(rtems_task_argument ignored)
/* check whether freechain put and get works correctly*/ /* check whether freechain put and get works correctly*/
_Freechain_Put(&fc, NULL);
puts( "INIT - Get node from freechain - OK" ); puts( "INIT - Get node from freechain - OK" );
node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node)); node = _Freechain_Get(&fc, malloc, 1, sizeof(test_node));
node->x = 1; node->x = 1;