Merge pull request #7151

4978f69 Fix byte_stream::put_n (Lee Clagett)
This commit is contained in:
luigi1111 2020-12-19 17:26:13 -06:00
commit 3bd6ed94d7
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010
2 changed files with 18 additions and 1 deletions

View File

@ -175,7 +175,7 @@ namespace epee
void put_n(const std::uint8_t ch, const std::size_t count) void put_n(const std::uint8_t ch, const std::size_t count)
{ {
check(count); check(count);
std::memset(tellp(), count, ch); std::memset(tellp(), ch, count);
next_write_ += count; next_write_ += count;
} }

View File

@ -982,6 +982,23 @@ TEST(ByteStream, Put)
EXPECT_TRUE(equal(bytes, byte_span{stream.data(), stream.size()})); 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) TEST(ByteStream, Reserve)
{ {
using boost::range::equal; using boost::range::equal;