diff options
-rw-r--r-- | Alc/hrtf.cpp | 2 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.cpp | 2 | ||||
-rw-r--r-- | common/almalloc.cpp | 4 | ||||
-rw-r--r-- | common/almalloc.h | 4 |
4 files changed, 8 insertions, 4 deletions
diff --git a/Alc/hrtf.cpp b/Alc/hrtf.cpp index 45f63c11..d1029aeb 100644 --- a/Alc/hrtf.cpp +++ b/Alc/hrtf.cpp @@ -66,7 +66,7 @@ struct HrtfHandle { std::unique_ptr<HrtfHandle> HrtfHandle::Create(size_t fname_len) { - void *ptr{al_calloc(DEF_ALIGN, HrtfHandle::Sizeof(fname_len))}; + void *ptr{al_calloc(alignof(HrtfHandle), HrtfHandle::Sizeof(fname_len))}; return std::unique_ptr<HrtfHandle>{new (ptr) HrtfHandle{fname_len}}; } diff --git a/OpenAL32/alAuxEffectSlot.cpp b/OpenAL32/alAuxEffectSlot.cpp index 44503436..ae038581 100644 --- a/OpenAL32/alAuxEffectSlot.cpp +++ b/OpenAL32/alAuxEffectSlot.cpp @@ -246,7 +246,7 @@ ALeffectslotArray *ALeffectslot::CreatePtrArray(size_t count) noexcept /* Allocate space for twice as many pointers, so the mixer has scratch * space to store a sorted list during mixing. */ - void *ptr{al_calloc(DEF_ALIGN, ALeffectslotArray::Sizeof(count*2))}; + void *ptr{al_calloc(alignof(ALeffectslotArray), ALeffectslotArray::Sizeof(count*2))}; return new (ptr) ALeffectslotArray{count}; } diff --git a/common/almalloc.cpp b/common/almalloc.cpp index 35b95001..f7af5bf3 100644 --- a/common/almalloc.cpp +++ b/common/almalloc.cpp @@ -3,6 +3,7 @@ #include "almalloc.h" +#include <cassert> #include <cstdlib> #include <cstring> #ifdef HAVE_MALLOC_H @@ -26,6 +27,9 @@ void *al_malloc(size_t alignment, size_t size) { + assert((alignment & (alignment-1)) == 0); + alignment = std::max(alignment, sizeof(void*)); + #if defined(HAVE_ALIGNED_ALLOC) size = (size+(alignment-1))&~(alignment-1); return aligned_alloc(alignment, size); diff --git a/common/almalloc.h b/common/almalloc.h index 406c2d31..0d77c46d 100644 --- a/common/almalloc.h +++ b/common/almalloc.h @@ -39,7 +39,7 @@ int al_is_sane_alignment_allocator(void) noexcept; namespace al { -template<typename T, size_t alignment=DEF_ALIGN> +template<typename T, size_t alignment=alignof(T)> struct allocator : public std::allocator<T> { using size_type = size_t; using pointer = T*; @@ -97,7 +97,7 @@ std::unique_ptr<T> make_unique(ArgsT&&...args) * struct, with placement new, to have a run-time-sized array that's embedded * with its size. */ -template<typename T,size_t alignment=DEF_ALIGN> +template<typename T, size_t alignment=alignof(T)> struct FlexArray { const size_t mSize; alignas(alignment) T mArray[]; |