@@ -448,70 +448,55 @@ static void prvInsertBlockIntoFreeList( BlockLink_t *pxBlockToInsert )
448
448
449
449
/*-----------------------------------------------------------*/
450
450
451
- void * pvPortRealloc ( void * pv , size_t xWantedSize )
452
- {
451
+ void * pvPortRealloc (void * pv , size_t xWantedSize ) {
453
452
size_t move_size ;
454
453
size_t block_size ;
455
454
BlockLink_t * pxLink ;
456
455
void * pvReturn = NULL ;
457
456
uint8_t * puc = (uint8_t * ) pv ;
458
457
459
- if (xWantedSize > 0 )
460
- {
461
- if (pv != NULL )
462
- {
463
- // The memory being freed will have an BlockLink_t structure immediately before it.
464
- puc -= xHeapStructSize ;
458
+ if (xWantedSize == 0 ) {
459
+ // Zero bytes requested, do nothing (according to libc, this behavior implementation defined)
460
+ return NULL ;
461
+ }
465
462
466
- // This casting is to keep the compiler from issuing warnings.
467
- pxLink = (void * ) puc ;
463
+ if (pv == NULL ) {
464
+ // pv points to NULL. Allocate a new buffer.
465
+ return pvPortMalloc (xWantedSize );
466
+ }
468
467
469
- // Check allocate block
470
- if ((pxLink -> xBlockSize & xBlockAllocatedBit ) != 0 )
471
- {
472
- // The block is being returned to the heap - it is no longer allocated.
473
- block_size = (pxLink -> xBlockSize & ~xBlockAllocatedBit ) - xHeapStructSize ;
468
+ // The memory being freed will have an BlockLink_t structure immediately before it.
469
+ puc -= xHeapStructSize ;
474
470
475
- // Allocate a new buffer
476
- pvReturn = pvPortMalloc ( xWantedSize ) ;
471
+ // This casting is to keep the compiler from issuing warnings.
472
+ pxLink = ( void * ) puc ;
477
473
478
- // Check creation and determine the data size to be copied to the new buffer
479
- if (pvReturn != NULL )
480
- {
481
- if (block_size < xWantedSize )
482
- {
483
- move_size = block_size ;
484
- }
485
- else
486
- {
487
- move_size = xWantedSize ;
488
- }
474
+ // Check allocate block
475
+ if ((pxLink -> xBlockSize & xBlockAllocatedBit ) != 0 ) {
476
+ // The block is being returned to the heap - it is no longer allocated.
477
+ block_size = (pxLink -> xBlockSize & ~xBlockAllocatedBit ) - xHeapStructSize ;
489
478
490
- // Copy the data from the old buffer to the new one
491
- memcpy ( pvReturn , pv , move_size );
479
+ // Allocate a new buffer
480
+ pvReturn = pvPortMalloc ( xWantedSize );
492
481
493
- // Free the old buffer
494
- vPortFree (pv );
495
- }
482
+ // Check creation and determine the data size to be copied to the new buffer
483
+ if (pvReturn != NULL ) {
484
+ if (block_size < xWantedSize ) {
485
+ move_size = block_size ;
486
+ } else {
487
+ move_size = xWantedSize ;
496
488
}
497
- else
498
- {
499
- // pv does not point to a valid memory buffer. Allocate a new one
500
- pvReturn = pvPortMalloc (xWantedSize );
501
- }
502
- }
503
- else
504
- {
505
- // pv points to NULL. Allocate a new buffer.
506
- pvReturn = pvPortMalloc (xWantedSize );
489
+
490
+ // Copy the data from the old buffer to the new one
491
+ memcpy (pvReturn , pv , move_size );
492
+
493
+ // Free the old buffer
494
+ vPortFree (pv );
507
495
}
508
- }
509
- else
510
- {
511
- // Zero bytes requested, do nothing (according to libc, this behavior implementation defined)
512
- pvReturn = NULL ;
496
+ } else {
497
+ // pv does not point to a valid memory buffer. Allocate a new one
498
+ pvReturn = pvPortMalloc (xWantedSize );
513
499
}
514
500
515
- // Exit with memory block
516
- return pvReturn ;
517
- }
501
+ return pvReturn ;
502
+ }
0 commit comments