Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken pvPortReallocMicroROS() implementation #48

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions extra_sources/custom_memory_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

#include <stdlib.h>
#include <string.h>

/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
all the API functions to use the MPU wrappers. That should only be done when
Expand Down Expand Up @@ -293,22 +294,17 @@ void *pvPortReallocMicroROS( void *pv, size_t xWantedSize )
vTaskSuspendAll();

void * newmem = pvPortMallocMicroROS(xWantedSize);
if (newmem != NULL)
{
size_t count = getBlockSize(pv) - xHeapStructSize;
pablogs9 marked this conversation as resolved.
Show resolved Hide resolved
if (xWantedSize < count)
{
count = xWantedSize;
}
memcpy(newmem, pv, count);

uint8_t *puc = ( uint8_t * ) pv;
BlockLink_t *pxLink;

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


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

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

vPortFreeMicroROS(pv);
vPortFreeMicroROS(pv);
}

( void ) xTaskResumeAll();

Expand Down Expand Up @@ -456,4 +452,4 @@ uint8_t *puc;
{
mtCOVERAGE_TEST_MARKER();
}
}
}