From e9781b225e5ba9d81b4bc0760e826902977fceeb Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 27 May 2019 08:27:25 -0700 Subject: [PATCH] Fix flat_buffer copy members fix #1621 --- CHANGELOG.md | 1 + include/boost/beast/core/impl/flat_buffer.hpp | 2 +- test/beast/core/test_buffer.hpp | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee56f0ff..30738989 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Version 257: * Remove redundant dependencies in http/server/fast example * Remove experimental/unit_test/thread.hpp * Use `if` statement in basic_stream::transfer_op +* Fix flat_buffer copy members -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/impl/flat_buffer.hpp b/include/boost/beast/core/impl/flat_buffer.hpp index f7fd5167..83d3b4e7 100644 --- a/include/boost/beast/core/impl/flat_buffer.hpp +++ b/include/boost/beast/core/impl/flat_buffer.hpp @@ -403,7 +403,7 @@ copy_from( if(begin_) { BOOST_ASSERT(other.begin_); - std::memcpy(begin_, other.begin_, n); + std::memcpy(begin_, other.in_, n); } } diff --git a/test/beast/core/test_buffer.hpp b/test/beast/core/test_buffer.hpp index f8e91859..8aff2edb 100644 --- a/test/beast/core/test_buffer.hpp +++ b/test/beast/core/test_buffer.hpp @@ -395,6 +395,14 @@ test_dynamic_buffer( BEAST_EXPECT( buffers_to_string(b1.data()) == buffers_to_string(b2.data())); + + // https://github.com/boostorg/beast/issues/1621 + b2.consume(1); + DynamicBuffer b3(b2); + BEAST_EXPECT(b3.size() == b2.size()); + BEAST_EXPECT( + buffers_to_string(b2.data()) == + buffers_to_string(b3.data())); } // move constructor @@ -422,6 +430,15 @@ test_dynamic_buffer( BEAST_EXPECT( buffers_to_string(b2.data()) == buffers_to_string(b1.data())); + + // https://github.com/boostorg/beast/issues/1621 + b2.consume(1); + DynamicBuffer b3(b2); + BEAST_EXPECT(b3.size() == b2.size()); + BEAST_EXPECT( + buffers_to_string(b2.data()) == + buffers_to_string(b3.data())); + } // move assignment