0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-29 10:12:39 +01:00

ircd::buffer: Use c++17 switch here; addl assertions.

This commit is contained in:
Jason Volk 2019-04-17 23:44:40 -07:00
parent 672dc48d1d
commit 286aee740b

View file

@ -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<char, decltype(&std::free)>
{
reinterpret_cast<char *>(ret), &std::free