Merge pull request #6 from kareem-wolfssl/realloc

Update example pvPortRealloc example.
master
David Garske 2023-07-20 09:48:55 -07:00 committed by GitHub
commit 37c7afab75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 24 deletions

View File

@ -312,21 +312,20 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if (xWantedSize == 0)
{
if (pv)
vPortFree(pv);
}
else if (pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - xHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= xHeapStructSize;
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
memcpy(pvReturn, pv, xWantedSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}

View File

@ -321,21 +321,20 @@ void *pvPortRealloc( void *pv, size_t xWantedSize )
{
void *pvReturn = NULL;
if (xWantedSize == 0)
{
if (pv)
vPortFree(pv);
}
else if (pv)
{
BlockLink_t *pxLink = (BlockLink_t *)((char*)pv - uxHeapStructSize);
if(pxLink->xBlockSize & xBlockAllocatedBit)
{
uint32_t blockSize = (pxLink->xBlockSize & ~xBlockAllocatedBit);
blockSize -= uxHeapStructSize;
pvReturn = pvPortMalloc(xWantedSize);
if(pvReturn)
{
memcpy(pvReturn, pv, blockSize);
memcpy(pvReturn, pv, xWantedSize);
vPortFree(pv);
}
}
}
else {
pvReturn = pvPortMalloc(xWantedSize);
}