mirror of
https://github.com/wiiu-env/wut.git
synced 2025-01-22 11:01:11 +01:00
Merge pull request #29 from shinyquagsire23/realloc
Realloc should only return the allocated pointer if it is passed a nullptr to rellocate
This commit is contained in:
commit
b41ae7993c
26
crt/memory.c
26
crt/memory.c
@ -20,15 +20,30 @@ __wrap_free(void *ptr) {
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
__wrap_malloc_usable_size(void *ptr) {
|
||||
return MEMGetSizeForMBlockExpHeap(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
__wrap_realloc(void *ptr, size_t size) {
|
||||
if (!ptr) {
|
||||
return __wrap_malloc(size);
|
||||
}
|
||||
|
||||
if (__wrap_malloc_usable_size(ptr) >= size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *realloc_ptr = __wrap_malloc(size);
|
||||
|
||||
if(realloc_ptr) {
|
||||
memcpy(realloc_ptr, ptr, size);
|
||||
__wrap_free(ptr);
|
||||
if(!realloc_ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr));
|
||||
__wrap_free(ptr);
|
||||
|
||||
return realloc_ptr;
|
||||
}
|
||||
|
||||
@ -43,11 +58,6 @@ __wrap_calloc(size_t num, size_t size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
size_t
|
||||
__wrap_malloc_usable_size(void *ptr) {
|
||||
return MEMGetSizeForMBlockExpHeap(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
__wrap_valloc(size_t size) {
|
||||
return __wrap_memalign(64, size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user