Skip to content

Commit 9b3b993

Browse files
committed
short circuit serializer::read on empty buffer
1 parent 7b16bf7 commit 9b3b993

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

include/boost/json/impl/serializer.ipp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@ read(char* dest, std::size_t size)
542542
if( !fn0_ )
543543
reset(nullptr);
544544

545+
if(BOOST_JSON_UNLIKELY(size == 0))
546+
return {dest, 0};
547+
545548
detail::stream ss(dest, size);
546549
if(st_.empty())
547550
fn0_(*this, ss);

test/serializer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ class serializer_test
896896
void
897897
run()
898898
{
899+
{
900+
serializer sr;
901+
BOOST_ASSERT( sr.read(nullptr, 0).empty() );
902+
}
899903
testNull();
900904
testBoolean();
901905
testString();

0 commit comments

Comments
 (0)