diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a322003..54cd2dc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Version 191: * Use lean_tuple in bind_handler, bind_front_handler * Use mp11 in detail::variant * Fix buffers_cat uninitialized warning +* Fix static_string uninitialized warning -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/detail/config.hpp b/include/boost/beast/core/detail/config.hpp index 68e3dda8..994db5a5 100644 --- a/include/boost/beast/core/detail/config.hpp +++ b/include/boost/beast/core/detail/config.hpp @@ -51,4 +51,13 @@ #define BOOST_BEAST_DEPRECATION_STRING \ "This is a deprecated interface, #define BOOST_BEAST_ALLOW_DEPRECATED to allow it" +#ifndef BOOST_BEAST_ASSUME +# ifdef BOOST_GCC +# define BOOST_BEAST_ASSUME(cond) \ + do { if (!(cond)) __builtin_unreachable(); } while (0) +# else +# define BOOST_BEAST_ASSUME(cond) do { } while(0) +# endif +#endif + #endif diff --git a/include/boost/beast/core/impl/static_string.ipp b/include/boost/beast/core/impl/static_string.ipp index 29571dfe..27274f4e 100644 --- a/include/boost/beast/core/impl/static_string.ipp +++ b/include/boost/beast/core/impl/static_string.ipp @@ -139,7 +139,9 @@ assign(static_string const& str) -> static_string& { n_ = str.n_; - Traits::copy(&s_[0], &str.s_[0], n_ + 1); + auto const n = n_ + 1; + BOOST_BEAST_ASSUME(n != 0); + Traits::copy(&s_[0], &str.s_[0], n); return *this; }