diff options
author | luigi1111 <luigi1111w@gmail.com> | 2020-12-19 17:26:51 -0600 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2020-12-19 17:26:51 -0600 |
commit | ee8d740cbaee242d008b446ddd4857c2f0fa43b9 (patch) | |
tree | 54a1f8a2ff68950940ef532b45d0218dfbf8a9f5 | |
parent | Merge pull request #7144 (diff) | |
parent | Fix byte_stream::put_n (diff) | |
download | monero-ee8d740cbaee242d008b446ddd4857c2f0fa43b9.tar.xz |
Merge pull request #7152
cf4461f Fix byte_stream::put_n (Lee Clagett)
-rw-r--r-- | contrib/epee/include/byte_stream.h | 2 | ||||
-rw-r--r-- | tests/unit_tests/epee_utils.cpp | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/contrib/epee/include/byte_stream.h b/contrib/epee/include/byte_stream.h index 42a9e1dd9..8e25c6650 100644 --- a/contrib/epee/include/byte_stream.h +++ b/contrib/epee/include/byte_stream.h @@ -188,7 +188,7 @@ namespace epee void put_n(const std::uint8_t ch, const std::size_t count) { check(count); - std::memset(tellp(), count, ch); + std::memset(tellp(), ch, count); next_write_ += count; } diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index b365cad86..8c89968b9 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -972,6 +972,23 @@ TEST(ByteStream, Put) EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()})); } +TEST(ByteStream, PutN) +{ + using boost::range::equal; + using byte_span = epee::span<const std::uint8_t>; + + std::vector<std::uint8_t> bytes; + bytes.resize(1000, 'f'); + + epee::byte_stream stream; + stream.put_n('f', 1000); + + EXPECT_EQ(1000u, stream.size()); + EXPECT_LE(1000u, stream.capacity()); + EXPECT_EQ(stream.available(), stream.capacity() - stream.size()); + EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()})); +} + TEST(ByteStream, Reserve) { using boost::range::equal; |