Skip to content

Commit

Permalink
Avoid UB in debug code
Browse files Browse the repository at this point in the history
`std::memset` calls with a nullptr argument are flagged as UB by GCC `-fsanitize=undefined`, so check the size first

Fixes boostorg#39
  • Loading branch information
Flamefire authored Sep 17, 2024
1 parent 05a8322 commit 598d346
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/boost/circular_buffer/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const int UNINITIALIZED = 0xcc;

template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
if(size_in_bytes)
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}

template <class T>
Expand Down

0 comments on commit 598d346

Please sign in to comment.