Commit 727e2b95 authored by Milo Yip's avatar Milo Yip Committed by GitHub

Merge pull request #673 from sjasonsmith/master

Fix buffer overrun using PutN (closes #672)
parents c79958a2 252e8122
......@@ -95,7 +95,7 @@ inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
//! Put N copies of a character to a stream.
template<typename Stream, typename Ch>
inline void PutN(Stream& stream, Ch c, size_t n) {
PutReserve<Stream>(stream, n);
PutReserve(stream, n);
for (size_t i = 0; i < n; i++)
PutUnsafe(stream, c);
}
......
......@@ -37,6 +37,13 @@ TEST(StringBuffer, Put) {
EXPECT_STREQ("A", buffer.GetString());
}
TEST(StringBuffer, PutN_Issue672) {
GenericStringBuffer<UTF8<>, MemoryPoolAllocator<> > buffer;
EXPECT_EQ(0, buffer.GetSize());
rapidjson::PutN(buffer, ' ', 1);
EXPECT_EQ(1, buffer.GetSize());
}
TEST(StringBuffer, Clear) {
StringBuffer buffer;
buffer.Put('A');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment