mirror of https://github.com/microsoft/mimalloc
merge from dev
This commit is contained in:
commit
31473c8e37
|
@ -224,6 +224,12 @@ static inline bool _mi_is_power_of_two(uintptr_t x) {
|
|||
return ((x & (x - 1)) == 0);
|
||||
}
|
||||
|
||||
// Is a pointer aligned?
|
||||
static inline bool _mi_is_aligned(void* p, size_t alignment) {
|
||||
mi_assert_internal(alignment != 0);
|
||||
return (((uintptr_t)p % alignment) == 0);
|
||||
}
|
||||
|
||||
// Align upwards
|
||||
static inline uintptr_t _mi_align_up(uintptr_t sz, size_t alignment) {
|
||||
mi_assert_internal(alignment != 0);
|
||||
|
|
|
@ -709,7 +709,7 @@ void* _mi_heap_realloc_zero(mi_heap_t* heap, void* p, size_t newsize, bool zero)
|
|||
memset((uint8_t*)newp + start, 0, newsize - start);
|
||||
}
|
||||
if mi_likely(p != NULL) {
|
||||
if mi_likely(_mi_is_aligned(p, sizeof(uintptr_t))) {
|
||||
if mi_likely(_mi_is_aligned(p, sizeof(uintptr_t))) { // a client may pass in an arbitrary pointer `p`..
|
||||
_mi_memcpy_aligned(newp, p, (newsize > size ? size : newsize));
|
||||
}
|
||||
mi_free(p); // only free the original pointer if successful
|
||||
|
|
Loading…
Reference in New Issue