From 258562545970a3b39e94027e2082d7b6212d6037 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 22 Nov 2018 08:05:39 -0800 Subject: [PATCH] Fix static_string uninitialized warning --- CHANGELOG.md | 1 + include/boost/beast/core/detail/config.hpp | 9 +++++++++ include/boost/beast/core/impl/static_string.ipp | 4 +++- 3 files changed, 13 insertions(+), 1 deletion(-) 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; }