diff options
author | Jacques Lucke <jacques@blender.org> | 2020-08-07 19:24:59 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-08-07 19:42:21 +0300 |
commit | c50e5fcc344d00b03eb4a3141b5b45944c3570fd (patch) | |
tree | f683ae1a1f38551d160a5be2ee86561d51faca26 /source/blender/blenlib/BLI_allocator.hh | |
parent | 28b10224346a9a2e55267f98357991a841eeda5b (diff) |
Cleanup: use C++ style casts in various places
Diffstat (limited to 'source/blender/blenlib/BLI_allocator.hh')
-rw-r--r-- | source/blender/blenlib/BLI_allocator.hh | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/source/blender/blenlib/BLI_allocator.hh b/source/blender/blenlib/BLI_allocator.hh index 3f753d1d81d..899c8499807 100644 --- a/source/blender/blenlib/BLI_allocator.hh +++ b/source/blender/blenlib/BLI_allocator.hh @@ -79,19 +79,20 @@ class RawAllocator { public: void *allocate(size_t size, size_t alignment, const char *UNUSED(name)) { - BLI_assert(is_power_of_2_i((int)alignment)); + BLI_assert(is_power_of_2_i(static_cast<int>(alignment))); void *ptr = malloc(size + alignment + sizeof(MemHead)); - void *used_ptr = (void *)((uintptr_t)POINTER_OFFSET(ptr, alignment + sizeof(MemHead)) & - ~((uintptr_t)alignment - 1)); - int offset = (int)((intptr_t)used_ptr - (intptr_t)ptr); - BLI_assert(offset >= (int)sizeof(MemHead)); - ((MemHead *)used_ptr - 1)->offset = (int)offset; + void *used_ptr = reinterpret_cast<void *>( + reinterpret_cast<uintptr_t>(POINTER_OFFSET(ptr, alignment + sizeof(MemHead))) & + ~(static_cast<uintptr_t>(alignment) - 1)); + int offset = static_cast<int>((intptr_t)used_ptr - (intptr_t)ptr); + BLI_assert(offset >= static_cast<int>(sizeof(MemHead))); + (static_cast<MemHead *>(used_ptr) - 1)->offset = offset; return used_ptr; } void deallocate(void *ptr) { - MemHead *head = (MemHead *)ptr - 1; + MemHead *head = static_cast<MemHead *>(ptr) - 1; int offset = -head->offset; void *actual_pointer = POINTER_OFFSET(ptr, offset); free(actual_pointer); |