Skip to content

Commit b7166f6

Browse files
committed
short circuit serializer::read on empty buffer
1 parent 7e2f458 commit b7166f6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/boost/json/impl/serializer.ipp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <boost/json/serializer.hpp>
1414
#include <boost/json/detail/format.hpp>
1515
#include <boost/json/detail/sse2.hpp>
16-
#include <ostream>
1716

1817
#ifdef _MSC_VER
1918
#pragma warning(push)
@@ -818,6 +817,9 @@ read(char* dest, std::size_t size)
818817
static value const null;
819818
jv_ = &null;
820819
}
820+
if(BOOST_JSON_UNLIKELY(size == 0))
821+
return {dest, 0};
822+
821823
return read_some(dest, size);
822824
}
823825

test/serializer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ class serializer_test
595595
void
596596
run()
597597
{
598+
{
599+
serializer sr;
600+
BOOST_ASSERT( sr.read(nullptr, 0).empty() );
601+
}
598602
testNull();
599603
testBoolean();
600604
testString();

0 commit comments

Comments
 (0)