diff --git a/src/ds/address.h b/src/ds/address.h index 0d829f2..4622d2a 100644 --- a/src/ds/address.h +++ b/src/ds/address.h @@ -18,19 +18,19 @@ namespace snmalloc /** * Perform pointer arithmetic and return the adjusted pointer. */ - template - inline T* pointer_offset(T* base, size_t diff) + template + inline U* pointer_offset(T* base, size_t diff) { - return reinterpret_cast(reinterpret_cast(base) + diff); + return reinterpret_cast(reinterpret_cast(base) + diff); } /** * Perform pointer arithmetic and return the adjusted pointer. */ - template - inline T* pointer_offset_signed(T* base, ptrdiff_t diff) + template + inline U* pointer_offset_signed(T* base, ptrdiff_t diff) { - return reinterpret_cast(reinterpret_cast(base) + diff); + return reinterpret_cast(reinterpret_cast(base) + diff); } /** diff --git a/src/ds/cdllist.h b/src/ds/cdllist.h index b1e79f7..3b7e146 100644 --- a/src/ds/cdllist.h +++ b/src/ds/cdllist.h @@ -31,7 +31,7 @@ namespace snmalloc SNMALLOC_FAST_PATH T* get_next() { - return pointer_offset_signed(static_cast(this), to_next); + return pointer_offset_signed(this, to_next); } }; diff --git a/src/mem/address_space.h b/src/mem/address_space.h index 7d4d6d9..b490e22 100644 --- a/src/mem/address_space.h +++ b/src/mem/address_space.h @@ -101,8 +101,7 @@ namespace snmalloc void* bigger = remove_block(align_bits + 1); if (bigger != nullptr) { - void* left_over = - pointer_offset(bigger, bits::one_at_bit(align_bits)); + auto left_over = pointer_offset(bigger, bits::one_at_bit(align_bits)); ranges[align_bits][0] = left_over; check_block(left_over, align_bits); } diff --git a/src/mem/alloc.h b/src/mem/alloc.h index 1ceb7e9..c44330a 100644 --- a/src/mem/alloc.h +++ b/src/mem/alloc.h @@ -391,7 +391,7 @@ namespace snmalloc while (chunkmap_slab_kind >= CMLargeRangeMin) { // This is a large alloc redirect. - ss = pointer_offset_signed( + ss = pointer_offset_signed( ss, -(static_cast(1) << (chunkmap_slab_kind - CMLargeRangeMin + SUPERSLAB_BITS))); @@ -402,7 +402,7 @@ namespace snmalloc { if constexpr ((location == End) || (location == OnePastEnd)) // We don't know the End, so return MAX_PTR - return pointer_offset(nullptr, UINTPTR_MAX); + return pointer_offset(nullptr, UINTPTR_MAX); else // We don't know the Start, so return MIN_PTR return nullptr; @@ -1181,8 +1181,8 @@ namespace snmalloc Slab* slab = alloc_slab(sizeclass); if (slab == nullptr) return nullptr; - bp = reinterpret_cast(pointer_offset( - slab, get_initial_offset(sizeclass, Metaslab::is_short(slab)))); + bp = pointer_offset( + slab, get_initial_offset(sizeclass, Metaslab::is_short(slab))); return small_alloc_build_free_list(sizeclass); } diff --git a/src/mem/superslab.h b/src/mem/superslab.h index cfe1e8e..61e7f90 100644 --- a/src/mem/superslab.h +++ b/src/mem/superslab.h @@ -183,8 +183,8 @@ namespace snmalloc Slab* alloc_slab(sizeclass_t sizeclass) { uint8_t h = head; - Slab* slab = pointer_offset( - reinterpret_cast(this), (static_cast(h) << SLAB_BITS)); + Slab* slab = reinterpret_cast( + pointer_offset(this, (static_cast(h) << SLAB_BITS))); uint8_t n = meta[h].next;