realloc: use copy_size to check for canaries
This avoids unnecessarily copying the canary when doing a realloc from a small size to a large size. It also avoids trying to copy a non-existent canary out of a zero-size allocation, which are memory protected.pull/87/head
parent
37474e117c
commit
bc75c4db7b
|
@ -1474,7 +1474,7 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
|||
return NULL;
|
||||
}
|
||||
size_t copy_size = min(size, old_size);
|
||||
if (size > 0 && size <= max_slab_size_class) {
|
||||
if (copy_size > 0 && copy_size <= max_slab_size_class) {
|
||||
copy_size -= canary_size;
|
||||
}
|
||||
memcpy(new, old, copy_size);
|
||||
|
|
Loading…
Reference in New Issue