From 286aee740b8ecb01477865e0b903cc89f31c5fe1 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 17 Apr 2019 23:44:40 -0700 Subject: [PATCH] ircd::buffer: Use c++17 switch here; addl assertions. --- include/ircd/buffer/unique_buffer.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/ircd/buffer/unique_buffer.h b/include/ircd/buffer/unique_buffer.h index 89f48d929..8e9027b2e 100644 --- a/include/ircd/buffer/unique_buffer.h +++ b/include/ircd/buffer/unique_buffer.h @@ -110,9 +110,12 @@ ircd::buffer::aligned_alloc(const size_t &align, align?: align_default }; - int errc; + assert(alignment % 2UL == 0); + assert(alignment % sizeof(void *) == 0); + assert(size % alignment == 0); + void *ret; - switch((errc = ::posix_memalign(&ret, alignment, size))) + switch(int errc(::posix_memalign(&ret, alignment, size)); errc) { case 0: break; @@ -127,6 +130,9 @@ ircd::buffer::aligned_alloc(const size_t &align, }; } + assert(ret != nullptr); + assert(uintptr_t(ret) % alignment == 0); + return std::unique_ptr { reinterpret_cast(ret), &std::free