From 2ab314e6878a2f9f7170a8747401450be5b13184 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 12 Nov 2018 16:49:06 -0800 Subject: [PATCH] ircd::buffer: Improve exceptions thrown from aligned_alloc(). --- include/ircd/buffer/unique_buffer.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/include/ircd/buffer/unique_buffer.h b/include/ircd/buffer/unique_buffer.h index bb4225926..94e3d59e0 100644 --- a/include/ircd/buffer/unique_buffer.h +++ b/include/ircd/buffer/unique_buffer.h @@ -119,14 +119,21 @@ ircd::buffer::aligned_alloc(const size_t &align, int errc; void *ret; - if(unlikely((errc = ::posix_memalign(&ret, alignment, size)) != 0)) - throw std::system_error - { - errc, std::system_category() - }; + switch((errc = ::posix_memalign(&ret, alignment, size))) + { + case 0: + break; + + case int(std::errc::not_enough_memory): + throw std::bad_alloc{}; + + default: + throw std::system_error + { + errc, std::system_category() + }; + } - assert(errc == 0); - assert(ret != nullptr); return std::unique_ptr { reinterpret_cast(ret), std::free