From 900d5314561904a396fd5528eb8fa8579f6f467e Mon Sep 17 00:00:00 2001 From: jnk0le Date: Wed, 17 Jan 2024 01:47:57 +0100 Subject: [PATCH] prevent use of non trivial objects before proper fix #23 Copy assignment into uninitialized array is UB. There is a potential "bounded" memory leak as well. --- ringbuffer.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ringbuffer.hpp b/ringbuffer.hpp index 3a980ec..2de25ed 100644 --- a/ringbuffer.hpp +++ b/ringbuffer.hpp @@ -1,6 +1,6 @@ /*! * \file ringbuffer.hpp - * \version 2.0.4 + * \version 2.0.5 * \brief Simple SPSC ring buffer implementation * * \author Jan Oleksiewicz @@ -38,7 +38,7 @@ namespace jnk0le /*! * \brief Special case constructor to premature out unnecessary initialization code when object is - * instatiated in .bss section + * instantiated in .bss section * \warning If object is instantiated on stack, heap or inside noinit section then the contents have to be * explicitly cleared before use * \param dummy Ignored @@ -343,9 +343,11 @@ namespace jnk0le "indexing type size is larger than size_t, operation is not lock free and doesn't make sense"); static_assert(std::numeric_limits::is_integer, "indexing type is not integral type"); - static_assert(!(std::numeric_limits::is_signed), "indexing type shall not be signed"); + static_assert(!(std::numeric_limits::is_signed), "indexing type must not be signed"); static_assert(buffer_mask <= ((std::numeric_limits::max)() >> 1), "buffer size is too large for a given indexing type (maximum size for n-bit type is 2^(n-1))"); + + static_assert(std::is_trivial::value, "non trivial objects will currently break"); }; template