Skip to content

Commit

Permalink
Fix pvPortRealloc (#99)
Browse files Browse the repository at this point in the history
* Fix pvPortRealloc

* Add check for NULL input pointer

* Modify if to one-liner

(cherry picked from commit d00d81a)
  • Loading branch information
Acuadros95 authored and mergify-bot committed Mar 25, 2022
1 parent 06924a6 commit 9ce2e2a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 57 deletions.
25 changes: 14 additions & 11 deletions microros_crazyflie21_extensions/src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,25 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )

void * newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = ( void * ) puc;
puc -= xHeapStructSize;
pxLink = ( void * ) puc;


char *in_src = (char*)pv;
char *in_dest = (char*)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char*)pv;
char *in_dest = (char*)newmem;

while(count--)
*in_dest++ = *in_src++;
size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

vPortFree(pv);
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
}

( void ) xTaskResumeAll();

Expand Down Expand Up @@ -463,4 +467,3 @@ uint8_t *puc;
mtCOVERAGE_TEST_MARKER();
}
}

23 changes: 14 additions & 9 deletions microros_nucleo_f446re_extensions/Core/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f446ze_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f746zg_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 14 additions & 9 deletions microros_nucleo_f767zi_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ void *pvPortRealloc(void *pv, size_t xWantedSize) {

void *newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = (uint8_t *)pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = (void *)puc;
puc -= xHeapStructSize;
pxLink = (void *)puc;

char *in_src = (char *)pv;
char *in_dest = (char *)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
char *in_src = (char *)pv;
char *in_dest = (char *)newmem;

size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while (count--) *in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

(void)xTaskResumeAll();

Expand Down
23 changes: 13 additions & 10 deletions microros_olimex_e407_extensions/Src/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,21 +300,24 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )

void * newmem = pvPortMalloc(xWantedSize);

uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;
if (newmem != NULL && pv != NULL)
{
uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;

puc -= xHeapStructSize;
pxLink = ( void * ) puc;
puc -= xHeapStructSize;
pxLink = ( void * ) puc;

char *in_src = (char*)pv;
char *in_dest = (char*)newmem;

char *in_src = (char*)pv;
char *in_dest = (char*)newmem;
size_t count = pxLink->xBlockSize & ~xBlockAllocatedBit;
size_t count = (pxLink->xBlockSize & ~xBlockAllocatedBit) - xHeapStructSize;
if (xWantedSize < count) count = xWantedSize;

while(count--)
*in_dest++ = *in_src++;
while (count--) *in_dest++ = *in_src++;

vPortFree(pv);
vPortFree(pv);
}

( void ) xTaskResumeAll();

Expand Down

0 comments on commit 9ce2e2a

Please sign in to comment.