From 598d346e8277d4ee1dd57d938eea3a222b040fc5 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 17 Sep 2024 19:57:40 +0200 Subject: [PATCH] Avoid UB in debug code `std::memset` calls with a nullptr argument are flagged as UB by GCC `-fsanitize=undefined`, so check the size first Fixes #39 --- include/boost/circular_buffer/debug.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/circular_buffer/debug.hpp b/include/boost/circular_buffer/debug.hpp index b6ab0fef..27bcbb8f 100644 --- a/include/boost/circular_buffer/debug.hpp +++ b/include/boost/circular_buffer/debug.hpp @@ -34,7 +34,8 @@ const int UNINITIALIZED = 0xcc; template inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT { - std::memset(static_cast(data), UNINITIALIZED, size_in_bytes); + if(size_in_bytes) + std::memset(static_cast(data), UNINITIALIZED, size_in_bytes); } template