alloc/malloc: remember to check memalign return value

This commit is contained in:
Danny Robson 2023-07-21 14:19:39 +10:00
parent aaa00bc989
commit 343b3d36ce

View File

@ -39,8 +39,8 @@ namespace cruft::alloc {
allocate (size_t count, size_t align) allocate (size_t count, size_t align)
{ {
void* ptr; void* ptr;
posix_memalign (&ptr, align, sizeof (T) * count); auto err = posix_memalign (&ptr, align, sizeof (T) * count);
if (!ptr) if (err or !ptr)
throw std::bad_alloc (); throw std::bad_alloc ();
return { reinterpret_cast<T*> (ptr), count }; return { reinterpret_cast<T*> (ptr), count };