mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 17:58:18 +03:00
LibC: Fix busted realloc() implementation.
This commit is contained in:
parent
df6aaaeeef
commit
3b42db0b4c
Notes:
sideshowbarker
2024-07-19 15:42:26 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3b42db0b4ca
@ -9,6 +9,7 @@
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <AK/StdLibExtras.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
@ -160,8 +161,11 @@ void* realloc(void *ptr, size_t size)
|
||||
validate_mallocation(ptr, "realloc()");
|
||||
auto* header = (MallocHeader*)((((byte*)ptr) - sizeof(MallocHeader)));
|
||||
size_t old_size = header->size;
|
||||
if (size == old_size)
|
||||
return ptr;
|
||||
auto* new_ptr = malloc(size);
|
||||
memcpy(new_ptr, ptr, old_size);
|
||||
memcpy(new_ptr, ptr, min(old_size, size));
|
||||
free(ptr);
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user